Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,12 +7,9 @@ API_URL = "https://startrz-devi.hf.space/api/v1/prediction/e54adffc-ae77-42e5-9f
|
|
7 |
# Function to query the API
|
8 |
def query(payload):
|
9 |
try:
|
10 |
-
response = requests.post(API_URL, json=payload
|
11 |
-
response.raise_for_status() # Raise for bad HTTP responses
|
12 |
-
|
13 |
-
return response.json() # Return JSON response
|
14 |
-
except ValueError:
|
15 |
-
return {"error": "Invalid JSON response from API"}
|
16 |
except requests.exceptions.RequestException as e:
|
17 |
return {"error": str(e)}
|
18 |
|
@@ -26,22 +23,19 @@ def main():
|
|
26 |
|
27 |
# Add a button to submit the query
|
28 |
if st.button("Submit"):
|
29 |
-
if user_input
|
30 |
# Send the user input to the API
|
31 |
with st.spinner("Fetching response..."):
|
32 |
response = query({
|
33 |
-
"question": user_input
|
34 |
-
"streaming": True
|
35 |
})
|
36 |
|
37 |
# Display the raw JSON response
|
38 |
-
|
39 |
-
|
40 |
-
else:
|
41 |
-
st.subheader("Raw JSON Response:")
|
42 |
-
st.json(response)
|
43 |
else:
|
44 |
st.warning("Please enter a question before submitting.")
|
45 |
|
46 |
if __name__ == "__main__":
|
47 |
-
main()
|
|
|
7 |
# Function to query the API
|
8 |
def query(payload):
|
9 |
try:
|
10 |
+
response = requests.post(API_URL, json=payload)
|
11 |
+
response.raise_for_status() # Raise an error for bad HTTP responses
|
12 |
+
return response.json() # Return the JSON response
|
|
|
|
|
|
|
13 |
except requests.exceptions.RequestException as e:
|
14 |
return {"error": str(e)}
|
15 |
|
|
|
23 |
|
24 |
# Add a button to submit the query
|
25 |
if st.button("Submit"):
|
26 |
+
if user_input:
|
27 |
# Send the user input to the API
|
28 |
with st.spinner("Fetching response..."):
|
29 |
response = query({
|
30 |
+
"question": user_input,
|
31 |
+
"streaming": True
|
32 |
})
|
33 |
|
34 |
# Display the raw JSON response
|
35 |
+
st.subheader("Raw JSON Response:")
|
36 |
+
st.json(response)
|
|
|
|
|
|
|
37 |
else:
|
38 |
st.warning("Please enter a question before submitting.")
|
39 |
|
40 |
if __name__ == "__main__":
|
41 |
+
main()
|