Spaces:
Runtime error
Runtime error
File size: 1,536 Bytes
7e02cc7 |
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 38 39 40 41 42 43 44 45 46 47 48 49 50 |
import streamlit as st
import requests
import json
def send_question_to_api(question):
url = 'http://localhost:5000/ask'
headers = {'Content-Type': 'application/json'}
data = {'question': question}
response = requests.post(url, headers=headers, data=json.dumps(data))
if response.status_code == 200:
return response.json().get('answer')
else:
return f"Error: {response.status_code} - {response.text}"
def main():
st.title("Financial Data Chatbot Tester")
st.write("Enter your question below and get a response from the chatbot.")
# Initialize session state to store question history
if 'history' not in st.session_state:
st.session_state.history = []
user_input = st.text_input("Your question:", "")
if st.button("Submit"):
if user_input:
with st.spinner('Getting the answer...'):
answer = send_question_to_api(user_input)
st.session_state.history.append((user_input, answer))
st.success(answer)
else:
st.warning("Please enter a question before submitting.")
# Display the history of questions and answers
if st.session_state.history:
st.write("### History")
for idx, (question, answer) in enumerate(st.session_state.history, 1):
st.write(f"**Q{idx}:** {question}")
st.write(f"**A{idx}:** {answer}")
st.write("---")
if __name__ == '__main__':
main()
|