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()