Tesneem commited on
Commit
d8c6b86
Β·
verified Β·
1 Parent(s): bfd4bd9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -17
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
- #select prompts to answer
331
- selected_questions = st.multiselect("βœ… Choose prompts to answer:", filtered_questions, default=filtered_questions)
332
-
333
- if selected_questions:
334
- with st.spinner("πŸ’‘ Generating answers..."):
335
- answers = []
336
- for q in selected_questions:
337
- full_query = f"{q}\n\nAdditional context:\n{uploaded_text}"
338
- response = rag_chain.invoke(full_query)
339
- answers.append({"question": q, "answer": response})
340
-
341
- for item in answers:
342
- st.markdown(f"### ❓ {item['question']}")
343
- st.markdown(f"πŸ’¬ {item['answer']}")
344
- else:
345
- st.info("No prompts selected for answering.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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")