fix check input api
Browse files
api.py
DELETED
@@ -1,25 +0,0 @@
|
|
1 |
-
"""API interactions for the Kwest API."""
|
2 |
-
|
3 |
-
import os
|
4 |
-
|
5 |
-
import requests
|
6 |
-
|
7 |
-
|
8 |
-
API_URL = os.getenv("API_URL", None)
|
9 |
-
AUTH_TOKEN = os.getenv("AUTH_TOKEN", None)
|
10 |
-
|
11 |
-
if not API_URL or not AUTH_TOKEN:
|
12 |
-
raise ValueError("API_URL and AUTH_TOKEN secrets must be set in the environment variables.")
|
13 |
-
|
14 |
-
|
15 |
-
def check_if_input_is_valid(input_str: str) -> bool:
|
16 |
-
"""Check if the input string is valid for the API."""
|
17 |
-
response = requests.post(
|
18 |
-
f"{API_URL}/check-input",
|
19 |
-
headers={"Authorization": f"{AUTH_TOKEN}"},
|
20 |
-
json={"input": input_str},
|
21 |
-
)
|
22 |
-
if response.status_code == 200:
|
23 |
-
return response.json()["output"]
|
24 |
-
else:
|
25 |
-
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
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,11 +15,11 @@ 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) ->
|
20 |
"""Check if the input string is valid for the API."""
|
21 |
response = requests.post(
|
22 |
-
f"{API_URL}
|
23 |
-
headers={"Authorization": f"{AUTH_TOKEN}"},
|
24 |
json={"input": input_str},
|
25 |
)
|
26 |
if response.status_code == 200:
|
@@ -62,7 +61,7 @@ with btn_col:
|
|
62 |
|
63 |
if check_input:
|
64 |
input_is_valid = check_if_input_is_valid(input_str)
|
65 |
-
if
|
66 |
st.error("An error occurred while checking the input. Please try again.")
|
67 |
st.stop()
|
68 |
else:
|
|
|
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 |
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) -> bool:
|
19 |
"""Check if the input string is valid for the API."""
|
20 |
response = requests.post(
|
21 |
+
f"{API_URL}input-check",
|
22 |
+
headers={"Authorization": f"{AUTH_TOKEN}", "Accept": "application/json"},
|
23 |
json={"input": input_str},
|
24 |
)
|
25 |
if response.status_code == 200:
|
|
|
61 |
|
62 |
if check_input:
|
63 |
input_is_valid = check_if_input_is_valid(input_str)
|
64 |
+
if input_is_valid is None:
|
65 |
st.error("An error occurred while checking the input. Please try again.")
|
66 |
st.stop()
|
67 |
else:
|