Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -102,31 +102,41 @@ precomputed_faq_answers = get_precomputed_answers()
|
|
| 102 |
# Streamlit UI
|
| 103 |
st.title('Mining Minerals Expert RAG App')
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
# Custom Question Section
|
| 106 |
st.subheader("Ask Your Own Question")
|
| 107 |
question = st.text_input('Write your question below:')
|
| 108 |
if st.button('Enter'):
|
| 109 |
if question:
|
| 110 |
answer = get_answer(question)
|
| 111 |
-
st.
|
|
|
|
| 112 |
else:
|
| 113 |
st.write("Please enter a question.")
|
| 114 |
-
|
| 115 |
-
# Sidebar with FAQ Section
|
| 116 |
-
st.sidebar.subheader("Frequently Asked Questions")
|
| 117 |
-
# Initialize session state to store the selected question and answer
|
| 118 |
-
if "faq_answer" not in st.session_state:
|
| 119 |
-
st.session_state.faq_answer = ""
|
| 120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
# Show initial 10 questions
|
| 122 |
faq_expander = st.sidebar.expander("FAQs")
|
| 123 |
with faq_expander:
|
| 124 |
for i, faq in enumerate(faq_questions):
|
| 125 |
if st.sidebar.button(f"Q{i+1}: {faq}", key=f"faq{i+1}"):
|
| 126 |
st.session_state.faq_answer = f"**Answer to Q{i+1}:** {precomputed_faq_answers[faq]}"
|
|
|
|
| 127 |
|
| 128 |
# Display the answer to the selected FAQ in the main window
|
| 129 |
if st.session_state.faq_answer:
|
| 130 |
st.write(st.session_state.faq_answer)
|
| 131 |
|
| 132 |
|
|
|
|
|
|
| 102 |
# Streamlit UI
|
| 103 |
st.title('Mining Minerals Expert RAG App')
|
| 104 |
|
| 105 |
+
# Sidebar with FAQ Section
|
| 106 |
+
st.sidebar.subheader("Frequently Asked Questions")
|
| 107 |
+
|
| 108 |
+
# Initialize session state to store the selected question and answer
|
| 109 |
+
if "faq_answer" not in st.session_state:
|
| 110 |
+
st.session_state.faq_answer = ""
|
| 111 |
+
if "custom_answer" not in st.session_state:
|
| 112 |
+
st.session_state.custom_answer = ""
|
| 113 |
+
|
| 114 |
# Custom Question Section
|
| 115 |
st.subheader("Ask Your Own Question")
|
| 116 |
question = st.text_input('Write your question below:')
|
| 117 |
if st.button('Enter'):
|
| 118 |
if question:
|
| 119 |
answer = get_answer(question)
|
| 120 |
+
st.session_state.custom_answer = f"**Answer:** {answer}"
|
| 121 |
+
st.session_state.faq_answer = "" # Clear FAQ answer when a custom question is asked
|
| 122 |
else:
|
| 123 |
st.write("Please enter a question.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
+
# Display the answer to the custom question in the main window
|
| 126 |
+
if st.session_state.custom_answer:
|
| 127 |
+
st.write(st.session_state.custom_answer)
|
| 128 |
+
|
| 129 |
# Show initial 10 questions
|
| 130 |
faq_expander = st.sidebar.expander("FAQs")
|
| 131 |
with faq_expander:
|
| 132 |
for i, faq in enumerate(faq_questions):
|
| 133 |
if st.sidebar.button(f"Q{i+1}: {faq}", key=f"faq{i+1}"):
|
| 134 |
st.session_state.faq_answer = f"**Answer to Q{i+1}:** {precomputed_faq_answers[faq]}"
|
| 135 |
+
st.session_state.custom_answer = "" # Clear custom answer when FAQ is clicked
|
| 136 |
|
| 137 |
# Display the answer to the selected FAQ in the main window
|
| 138 |
if st.session_state.faq_answer:
|
| 139 |
st.write(st.session_state.faq_answer)
|
| 140 |
|
| 141 |
|
| 142 |
+
|