File size: 1,211 Bytes
6a79c8b
c89022e
6a79c8b
39dedf4
3109ca4
6a79c8b
39dedf4
 
 
05a30e5
39dedf4
 
 
05a30e5
39dedf4
0697206
39dedf4
 
34c0423
39dedf4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c89022e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import streamlit as st
import requests

# API URL
API_URL = "https://startrz-proagents.hf.space/api/v1/prediction/5e21b535-6568-4acb-94a7-076a6996181e"

# Function to query the API
def query_api(question):
    payload = {"question": question}
    try:
        response = requests.post(API_URL, json=payload)
        response.raise_for_status()  # Raise an error for bad responses
        return response.json()  # Return the JSON response
    except requests.exceptions.RequestException as e:
        return {"error": str(e)}  # Return the error message

# Streamlit app title
st.title("API Query App")

# User input for the question
user_question = st.text_input("Ask a question:")

# Submit button
if st.button("Submit"):
    if user_question:
        with st.spinner("Fetching response..."):
            output = query_api(user_question)
            if "error" in output:
                st.error(f"Error: {output['error']}")
            else:
                # Display the response from the API
                st.subheader("Response:")
                st.write(output)  # Adjust this line based on the expected response structure
    else:
        st.warning("Please enter a question before submitting.")