-
Notifications
You must be signed in to change notification settings - Fork 0
/
streamlit_app.py
67 lines (54 loc) · 2.06 KB
/
streamlit_app.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import streamlit as st
from logic import QuestionHandler
def get_answer_for_question(question: str, model: str = "gpt-3.5-turbo") -> dict:
"""call the logic to get the answer to the question"""
question_handler = QuestionHandler(question, model)
answer = question_handler.get_answer()
return answer
def main():
"""
This function creates a Streamlit app for a question-answering system. It allows the user to input a question,
select a model to use, and get an answer. It also displays previous questions and answers.
Returns:
None
"""
st.title("Question-Answering App")
# Input for the user to type in their question
question = st.text_input("Enter your question:")
# Model selection
model = st.selectbox(
"Select the model you want to use:",
["gpt-3.5-turbo"],
)
# Button to get the answer
if st.button("Get Answer"):
if question:
answer = get_answer_for_question(question, model)
if answer["Missing_information"]:
st.warning(
"Missing information to answer the question. Please try again."
)
else:
st.write(f"Answer: {answer['Answer']}")
else:
st.warning("Please enter a question.")
# Display past questions and answers
with st.expander("Previous Questions and Answers"):
# Store questions and answers in session state
if not hasattr(st.session_state, "qa_pairs"):
st.session_state.qa_pairs = []
for qa_pair in st.session_state.qa_pairs:
st.write(f"Q: {qa_pair['question']}")
st.write(f"A: {qa_pair['answer']}")
# Update session state with current question and answer
if question:
st.session_state.qa_pairs.append(
{
"question": question,
"answer": get_answer_for_question(question, model).get(
"Answer", ""
),
}
)
if __name__ == "__main__":
main()