add recipe choice
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
"""kwest.dev is a saas tool to craft stories for your ideas."""
|
| 2 |
|
| 3 |
import os
|
|
|
|
| 4 |
|
| 5 |
import requests
|
| 6 |
import streamlit as st
|
|
@@ -15,7 +16,7 @@ if not API_URL or not AUTH_TOKEN:
|
|
| 15 |
raise ValueError("API_URL and AUTH_TOKEN secrets must be set in the environment variables.")
|
| 16 |
|
| 17 |
|
| 18 |
-
def check_if_input_is_valid(input_str: str) ->
|
| 19 |
"""Check if the input string is valid for the API."""
|
| 20 |
response = requests.post(
|
| 21 |
f"{API_URL}input-check",
|
|
@@ -28,6 +29,32 @@ def check_if_input_is_valid(input_str: str) -> bool:
|
|
| 28 |
return None
|
| 29 |
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
# UI
|
| 32 |
st.title("kwest.dev")
|
| 33 |
st.subheader("Leverage the power of storytelling for any idea. 💡")
|
|
@@ -72,5 +99,16 @@ if check_input:
|
|
| 72 |
)
|
| 73 |
|
| 74 |
if input_is_valid["objective"] == "yes" and input_is_valid["context"] == "yes" and input_is_valid["audience"] == "yes":
|
|
|
|
| 75 |
st.write("Choose the recipe you want to use for your story.")
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
"""kwest.dev is a saas tool to craft stories for your ideas."""
|
| 2 |
|
| 3 |
import os
|
| 4 |
+
from typing import Union
|
| 5 |
|
| 6 |
import requests
|
| 7 |
import streamlit as st
|
|
|
|
| 16 |
raise ValueError("API_URL and AUTH_TOKEN secrets must be set in the environment variables.")
|
| 17 |
|
| 18 |
|
| 19 |
+
def check_if_input_is_valid(input_str: str) -> Union[dict[str, str], None]:
|
| 20 |
"""Check if the input string is valid for the API."""
|
| 21 |
response = requests.post(
|
| 22 |
f"{API_URL}input-check",
|
|
|
|
| 29 |
return None
|
| 30 |
|
| 31 |
|
| 32 |
+
def get_recipe_choices(input_str: str) -> Union[dict[str, str], None]:
|
| 33 |
+
"""Get the recipe choices for the input string."""
|
| 34 |
+
response = requests.post(
|
| 35 |
+
f"{API_URL}recipe-choice",
|
| 36 |
+
headers={"Authorization": f"{AUTH_TOKEN}", "Accept": "application/json"},
|
| 37 |
+
json={"input": input_str},
|
| 38 |
+
)
|
| 39 |
+
if response.status_code == 200:
|
| 40 |
+
return response.json()["output"]["recipes"]
|
| 41 |
+
else:
|
| 42 |
+
return None
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def craft_story_from_recipe(input_str: str, recipe: str) -> Union[dict[str, str], None]:
|
| 46 |
+
"""Craft a story from the input string and recipe."""
|
| 47 |
+
response = requests.post(
|
| 48 |
+
f"{API_URL}craft-from-recipe",
|
| 49 |
+
headers={"Authorization": f"{AUTH_TOKEN}", "Accept": "application/json"},
|
| 50 |
+
json={"input": input_str, "recipe": recipe},
|
| 51 |
+
)
|
| 52 |
+
if response.status_code == 200:
|
| 53 |
+
return response.json()["output"]
|
| 54 |
+
else:
|
| 55 |
+
return None
|
| 56 |
+
|
| 57 |
+
|
| 58 |
# UI
|
| 59 |
st.title("kwest.dev")
|
| 60 |
st.subheader("Leverage the power of storytelling for any idea. 💡")
|
|
|
|
| 99 |
)
|
| 100 |
|
| 101 |
if input_is_valid["objective"] == "yes" and input_is_valid["context"] == "yes" and input_is_valid["audience"] == "yes":
|
| 102 |
+
recipe_choices = get_recipe_choices(input_str)
|
| 103 |
st.write("Choose the recipe you want to use for your story.")
|
| 104 |
|
| 105 |
+
choice_1, choice_2 = st.columns(2)
|
| 106 |
+
other_choices = st.columns(5)
|
| 107 |
+
|
| 108 |
+
with choice_1:
|
| 109 |
+
recipe_1 = st.button(recipe_choices["recipe"])
|
| 110 |
+
with choice_2:
|
| 111 |
+
recipe_2 = st.button(recipe_choices["second_recipe"])
|
| 112 |
+
for idx, recipe in enumerate(RECIPES - {recipe_choices["recipe"], recipe_choices["second_recipe"]}):
|
| 113 |
+
with other_choices[idx]:
|
| 114 |
+
other_recipe = st.button(recipe)
|