Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -326,23 +326,46 @@ def main():
|
|
| 326 |
return not (too_short or contains_bad_word or is_just_punctuation)
|
| 327 |
|
| 328 |
filtered_questions = [q for q in questions if is_meaningful_prompt(q)]
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 346 |
|
| 347 |
# βοΈ Manual single-question input
|
| 348 |
query = st.text_input("Ask a grant-related question")
|
|
|
|
| 326 |
return not (too_short or contains_bad_word or is_just_punctuation)
|
| 327 |
|
| 328 |
filtered_questions = [q for q in questions if is_meaningful_prompt(q)]
|
| 329 |
+
with st.form("question_selection_form"):
|
| 330 |
+
st.subheader("Choose prompts to answer:")
|
| 331 |
+
selected_questions=[]
|
| 332 |
+
for i,q in enumerate(filtered_questions):
|
| 333 |
+
if st.checkbox(q, key=f"q_{i}", value=True):
|
| 334 |
+
selected_questions.append(q)
|
| 335 |
+
submit_button = st.form_submit_button("Submit")
|
| 336 |
+
|
| 337 |
+
if 'submit_button' in locals() and submit_button:
|
| 338 |
+
if selected_questions:
|
| 339 |
+
with st.spinner("π‘ Generating answers..."):
|
| 340 |
+
answers = []
|
| 341 |
+
for q in selected_questions:
|
| 342 |
+
full_query = f"{q}\n\nAdditional context:\n{uploaded_text}"
|
| 343 |
+
response = rag_chain.invoke(full_query)
|
| 344 |
+
answers.append({"question": q, "answer": response})
|
| 345 |
+
for item in answers:
|
| 346 |
+
st.markdown(f"### β {item['question']}")
|
| 347 |
+
st.markdown(f"π¬ {item['answer']}")
|
| 348 |
+
else:
|
| 349 |
+
st.info("No prompts selected for answering.")
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
# #select prompts to answer
|
| 354 |
+
# selected_questions = st.multiselect("β
Choose prompts to answer:", filtered_questions, default=filtered_questions)
|
| 355 |
+
|
| 356 |
+
# if selected_questions:
|
| 357 |
+
# with st.spinner("π‘ Generating answers..."):
|
| 358 |
+
# answers = []
|
| 359 |
+
# for q in selected_questions:
|
| 360 |
+
# full_query = f"{q}\n\nAdditional context:\n{uploaded_text}"
|
| 361 |
+
# response = rag_chain.invoke(full_query)
|
| 362 |
+
# answers.append({"question": q, "answer": response})
|
| 363 |
+
|
| 364 |
+
# for item in answers:
|
| 365 |
+
# st.markdown(f"### β {item['question']}")
|
| 366 |
+
# st.markdown(f"π¬ {item['answer']}")
|
| 367 |
+
# else:
|
| 368 |
+
# st.info("No prompts selected for answering.")
|
| 369 |
|
| 370 |
# βοΈ Manual single-question input
|
| 371 |
query = st.text_input("Ask a grant-related question")
|