Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,45 +4,27 @@ import requests
|
|
4 |
# API URL
|
5 |
API_URL = "https://startrz-proagents.hf.space/api/v1/prediction/7fae8aea-4e25-4feb-8af3-f08e2cd0c020"
|
6 |
|
|
|
7 |
def query(payload):
|
8 |
-
|
9 |
-
|
10 |
-
"""
|
11 |
-
try:
|
12 |
-
response = requests.post(API_URL, json=payload)
|
13 |
-
response.raise_for_status() # Raise error for bad responses (4xx, 5xx)
|
14 |
-
return response.json()
|
15 |
-
except requests.exceptions.HTTPError as http_err:
|
16 |
-
return {"error": f"HTTP error occurred: {http_err}"}
|
17 |
-
except requests.exceptions.RequestException as req_err:
|
18 |
-
return {"error": f"Request error occurred: {req_err}"}
|
19 |
|
20 |
-
# Streamlit
|
21 |
-
|
22 |
-
st.
|
23 |
-
Submit your question or task, and get an intelligent response from the system.
|
24 |
-
""")
|
25 |
|
26 |
-
# Input
|
27 |
-
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
# Query the API
|
33 |
-
st.markdown(f"**Submitted Question:** {question}")
|
34 |
-
response = query({"question": question})
|
35 |
|
36 |
-
# Display the
|
37 |
-
if "
|
38 |
-
st.
|
39 |
else:
|
40 |
-
|
41 |
-
st.success("Response received:")
|
42 |
-
st.markdown(f"**Answer:** {answer}")
|
43 |
-
else:
|
44 |
-
st.warning("Please enter a question or task before submitting.")
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
st.markdown("Built with ❤️ using [Streamlit](https://streamlit.io).")
|
|
|
4 |
# API URL
|
5 |
API_URL = "https://startrz-proagents.hf.space/api/v1/prediction/7fae8aea-4e25-4feb-8af3-f08e2cd0c020"
|
6 |
|
7 |
+
# Function to query the API
|
8 |
def query(payload):
|
9 |
+
response = requests.post(API_URL, json=payload)
|
10 |
+
return response.json()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
# Streamlit app
|
13 |
+
def main():
|
14 |
+
st.title("DEVI RESEARCH")
|
|
|
|
|
15 |
|
16 |
+
# Input box for user query
|
17 |
+
user_input = st.text_input("Ask a question:")
|
18 |
|
19 |
+
if user_input:
|
20 |
+
# Send the user input to the API
|
21 |
+
response = query({"question": user_input})
|
|
|
|
|
|
|
22 |
|
23 |
+
# Display the response from the API
|
24 |
+
if response.get("answer"):
|
25 |
+
st.write(f"Response: {response['answer']}")
|
26 |
else:
|
27 |
+
st.write("No answer received, please try again.")
|
|
|
|
|
|
|
|
|
28 |
|
29 |
+
if __name__ == "__main__":
|
30 |
+
main()
|
|