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.")