add craft story
Browse files
app.py
CHANGED
|
@@ -42,7 +42,7 @@ def get_recipe_choices(input_str: str) -> Union[dict[str, str], None]:
|
|
| 42 |
return None
|
| 43 |
|
| 44 |
|
| 45 |
-
def craft_story_from_recipe(input_str: str, recipe: str) ->
|
| 46 |
"""Craft a story from the input string and recipe."""
|
| 47 |
response = requests.post(
|
| 48 |
f"{API_URL}craft-from-recipe",
|
|
@@ -50,9 +50,9 @@ def craft_story_from_recipe(input_str: str, recipe: str) -> Union[dict[str, str]
|
|
| 50 |
json={"input": input_str, "recipe": recipe},
|
| 51 |
)
|
| 52 |
if response.status_code == 200:
|
| 53 |
-
|
| 54 |
else:
|
| 55 |
-
|
| 56 |
|
| 57 |
|
| 58 |
# UI
|
|
@@ -106,9 +106,22 @@ if check_input:
|
|
| 106 |
other_choices = st.columns(5)
|
| 107 |
|
| 108 |
with choice_1:
|
| 109 |
-
recipe_1 = st.button(
|
|
|
|
|
|
|
|
|
|
| 110 |
with choice_2:
|
| 111 |
-
recipe_2 = st.button(
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
| 113 |
with other_choices[idx]:
|
| 114 |
-
other_recipe = st.button(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
return None
|
| 43 |
|
| 44 |
|
| 45 |
+
def craft_story_from_recipe(input_str: str, recipe: str) -> None:
|
| 46 |
"""Craft a story from the input string and recipe."""
|
| 47 |
response = requests.post(
|
| 48 |
f"{API_URL}craft-from-recipe",
|
|
|
|
| 50 |
json={"input": input_str, "recipe": recipe},
|
| 51 |
)
|
| 52 |
if response.status_code == 200:
|
| 53 |
+
st.session_state.story = response.json()["output"]["story"]
|
| 54 |
else:
|
| 55 |
+
raise ValueError("An error occurred while crafting the story.")
|
| 56 |
|
| 57 |
|
| 58 |
# UI
|
|
|
|
| 106 |
other_choices = st.columns(5)
|
| 107 |
|
| 108 |
with choice_1:
|
| 109 |
+
recipe_1 = st.button(
|
| 110 |
+
recipe_choices["recipe"],
|
| 111 |
+
on_click=lambda: craft_story_from_recipe(input_str, recipe_choices["recipe"])
|
| 112 |
+
)
|
| 113 |
with choice_2:
|
| 114 |
+
recipe_2 = st.button(
|
| 115 |
+
recipe_choices["second_recipe"],
|
| 116 |
+
on_click=lambda: craft_story_from_recipe(input_str, recipe_choices["second_recipe"])
|
| 117 |
+
)
|
| 118 |
+
for idx, recipe in enumerate(RECIPES - [recipe_choices["recipe"], recipe_choices["second_recipe"]]):
|
| 119 |
with other_choices[idx]:
|
| 120 |
+
other_recipe = st.button(
|
| 121 |
+
recipe,
|
| 122 |
+
on_click=lambda: craft_story_from_recipe(input_str, recipe)
|
| 123 |
+
)
|
| 124 |
+
|
| 125 |
+
if "story" in st.session_state:
|
| 126 |
+
st.markdown(st.session_state.story)
|
| 127 |
+
del st.session_state.story
|