Update app.py
Browse files
app.py
CHANGED
|
@@ -132,8 +132,6 @@ def build_index(files, progress=gr.Progress()):
|
|
| 132 |
# ---- RAG query -> retrieve -> generate ----
|
| 133 |
def answer_question(question, top_k=5, max_new_tokens=256, progress=gr.Progress()):
|
| 134 |
|
| 135 |
-
progress(0.1, desc="Embedding question…")
|
| 136 |
-
|
| 137 |
if index is None or not corpus_chunks:
|
| 138 |
return "Index not built yet. Upload PDFs and click **Build Index** first."
|
| 139 |
|
|
@@ -151,8 +149,6 @@ def answer_question(question, top_k=5, max_new_tokens=256, progress=gr.Progress(
|
|
| 151 |
f"Context:\n{context}\n\nQuestion: {question}\nAnswer:"
|
| 152 |
)
|
| 153 |
|
| 154 |
-
progress(0.6, desc="Generating answer…")
|
| 155 |
-
|
| 156 |
out = generator(prompt, max_new_tokens=int(max_new_tokens), temperature=0.2)
|
| 157 |
return out[0]["generated_text"].strip()
|
| 158 |
|
|
@@ -207,7 +203,9 @@ with gr.Blocks(title="Group 5 Study Helper (RAG)") as demo:
|
|
| 207 |
return msg, n or 0
|
| 208 |
|
| 209 |
build_btn.click(_build, inputs=[file_in], outputs=[status, chunk_count])
|
| 210 |
-
ask_btn.click(
|
|
|
|
|
|
|
| 211 |
reset_btn.click(
|
| 212 |
reset_app,
|
| 213 |
inputs=None,
|
|
|
|
| 132 |
# ---- RAG query -> retrieve -> generate ----
|
| 133 |
def answer_question(question, top_k=5, max_new_tokens=256, progress=gr.Progress()):
|
| 134 |
|
|
|
|
|
|
|
| 135 |
if index is None or not corpus_chunks:
|
| 136 |
return "Index not built yet. Upload PDFs and click **Build Index** first."
|
| 137 |
|
|
|
|
| 149 |
f"Context:\n{context}\n\nQuestion: {question}\nAnswer:"
|
| 150 |
)
|
| 151 |
|
|
|
|
|
|
|
| 152 |
out = generator(prompt, max_new_tokens=int(max_new_tokens), temperature=0.2)
|
| 153 |
return out[0]["generated_text"].strip()
|
| 154 |
|
|
|
|
| 203 |
return msg, n or 0
|
| 204 |
|
| 205 |
build_btn.click(_build, inputs=[file_in], outputs=[status, chunk_count])
|
| 206 |
+
evt = ask_btn.click(lambda: "⏳ Processing…", inputs=None, outputs=answer)
|
| 207 |
+
evt.then(answer_question, inputs=[question, topk, max_tokens], outputs=answer)
|
| 208 |
+
|
| 209 |
reset_btn.click(
|
| 210 |
reset_app,
|
| 211 |
inputs=None,
|