Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,9 +7,12 @@ 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
|
12 |
-
|
|
|
|
|
|
|
13 |
except requests.exceptions.RequestException as e:
|
14 |
return {"error": str(e)}
|
15 |
|
@@ -23,19 +26,22 @@ def main():
|
|
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 |
-
|
36 |
-
|
|
|
|
|
|
|
37 |
else:
|
38 |
st.warning("Please enter a question before submitting.")
|
39 |
|
40 |
if __name__ == "__main__":
|
41 |
-
main()
|
|
|
7 |
# Function to query the API
|
8 |
def query(payload):
|
9 |
try:
|
10 |
+
response = requests.post(API_URL, json=payload, timeout=30) # Increased timeout
|
11 |
+
response.raise_for_status() # Raise for bad HTTP responses
|
12 |
+
try:
|
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 |
|
27 |
# Add a button to submit the query
|
28 |
if st.button("Submit"):
|
29 |
+
if user_input.strip():
|
30 |
# Send the user input to the API
|
31 |
with st.spinner("Fetching response..."):
|
32 |
response = query({
|
33 |
+
"question": user_input.strip(),
|
34 |
+
"streaming": True # Verify if this parameter is supported
|
35 |
})
|
36 |
|
37 |
# Display the raw JSON response
|
38 |
+
if "error" in response:
|
39 |
+
st.error(f"Error: {response['error']}")
|
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()
|