ositamiles commited on
Commit
798ac46
·
verified ·
1 Parent(s): 3a9a144

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -35
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
- Query the API with the given payload.
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 App
21
- st.title("Devi Research Task Interface")
22
- st.markdown("""
23
- Submit your question or task, and get an intelligent response from the system.
24
- """)
25
 
26
- # Input Field
27
- question = st.text_area("Enter your question or task:", help="Type your query here.")
28
 
29
- # Submit Button
30
- if st.button("Submit"):
31
- if question.strip():
32
- # Query the API
33
- st.markdown(f"**Submitted Question:** {question}")
34
- response = query({"question": question})
35
 
36
- # Display the Result
37
- if "error" in response:
38
- st.error(f"Error: {response['error']}")
39
  else:
40
- answer = response.get("answer", "No answer returned.")
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
- # Footer
47
- st.markdown("---")
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()