chainyo commited on
Commit
a081a02
·
1 Parent(s): 3398004

fix input check

Browse files
Files changed (1) hide show
  1. app.py +37 -16
app.py CHANGED
@@ -1,13 +1,35 @@
1
  """kwest.dev is a saas tool to craft stories for your ideas."""
2
 
 
 
 
 
3
  import streamlit as st
4
 
5
- from api import check_if_input_is_valid
6
 
 
 
7
  RECIPES = ["sell", "motivate", "convince", "connect", "explain", "lead", "impress"]
8
  VALID_EMOJIS = {"yes": "✅", "no": "❌"}
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
 
 
11
  st.title("kwest.dev")
12
  st.subheader("Leverage the power of storytelling for any idea. 💡")
13
 
@@ -36,21 +58,20 @@ input_col, btn_col = st.columns([3, 1], vertical_alignment="bottom")
36
  with input_col:
37
  input_str = st.text_area("Your idea that needs a story", "", placeholder="I need a pitch for ...")
38
  with btn_col:
39
- input_is_valid = st.button(
40
- label="▶️",
41
- key="check_input",
42
- help="Check if the input is valid",
43
- on_click=check_if_input_is_valid,
44
- kwargs={"input_str": input_str}
45
- )
46
 
47
- if input_is_valid is not None:
48
- st.write(
49
- f"Objective: {VALID_EMOJIS[input_is_valid['objective']]} | "
50
- f"Context: {VALID_EMOJIS[input_is_valid['context']]} | "
51
- f"Audience: {VALID_EMOJIS[input_is_valid['audience']]}"
52
- )
 
 
 
 
 
53
 
54
- if input_is_valid["objective"] == "yes" and input_is_valid["context"] == "yes" and input_is_valid["audience"] == "yes":
55
- st.write("Choose the recipe you want to use for your story.")
56
 
 
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
8
 
 
9
 
10
+ API_URL = os.getenv("API_URL", None)
11
+ AUTH_TOKEN = os.getenv("AUTH_TOKEN", None)
12
  RECIPES = ["sell", "motivate", "convince", "connect", "explain", "lead", "impress"]
13
  VALID_EMOJIS = {"yes": "✅", "no": "❌"}
14
 
15
+ if not API_URL or not AUTH_TOKEN:
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, None]:
20
+ """Check if the input string is valid for the API."""
21
+ response = requests.post(
22
+ f"{API_URL}/check-input",
23
+ headers={"Authorization": f"{AUTH_TOKEN}"},
24
+ json={"input": input_str},
25
+ )
26
+ if response.status_code == 200:
27
+ return response.json()["output"]
28
+ else:
29
+ return None
30
 
31
+
32
+ # UI
33
  st.title("kwest.dev")
34
  st.subheader("Leverage the power of storytelling for any idea. 💡")
35
 
 
58
  with input_col:
59
  input_str = st.text_area("Your idea that needs a story", "", placeholder="I need a pitch for ...")
60
  with btn_col:
61
+ check_input = st.button(label="▶️", key="check_input", help="Check if the input is valid")
 
 
 
 
 
 
62
 
63
+ if check_input:
64
+ input_is_valid = check_if_input_is_valid(input_str)
65
+ if not input_is_valid:
66
+ st.error("An error occurred while checking the input. Please try again.")
67
+ st.stop()
68
+ else:
69
+ st.write(
70
+ f"Objective: {VALID_EMOJIS[input_is_valid['objective']]} | "
71
+ f"Context: {VALID_EMOJIS[input_is_valid['context']]} | "
72
+ f"Audience: {VALID_EMOJIS[input_is_valid['audience']]}"
73
+ )
74
 
75
+ if input_is_valid["objective"] == "yes" and input_is_valid["context"] == "yes" and input_is_valid["audience"] == "yes":
76
+ st.write("Choose the recipe you want to use for your story.")
77