MarshallCN commited on
Commit ·
cca4fcc
1
Parent(s): 95b70b5
update pdf req
Browse files- app.py +26 -7
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -482,11 +482,12 @@ def on_send(user_text: str,
|
|
| 482 |
else:
|
| 483 |
user_text_aug = user_text
|
| 484 |
|
| 485 |
-
# 4) append user
|
| 486 |
-
|
|
|
|
| 487 |
|
| 488 |
prompt, max_new = render_qwen_trim(
|
| 489 |
-
messages=
|
| 490 |
model=model,
|
| 491 |
n_ctx=None,
|
| 492 |
add_generation_prompt=True,
|
|
@@ -520,18 +521,18 @@ def on_send(user_text: str,
|
|
| 520 |
reply = str(_out).strip()
|
| 521 |
|
| 522 |
# 5) append assistant + persist
|
| 523 |
-
messages =
|
| 524 |
|
| 525 |
if msg_id:
|
| 526 |
msg_dir = _as_dir(BASE_MSG_DIR, msg_id)
|
| 527 |
persist_messages(messages, msg_dir, archive_last_turn=True)
|
| 528 |
|
| 529 |
-
return "", messages, visible_chat(messages), msg_id, sessions_update, sessions, gr.update(value=rag_context_text, visible=
|
| 530 |
|
| 531 |
|
| 532 |
# ===================== UI =====================
|
| 533 |
-
with gr.Blocks(title="Qwen
|
| 534 |
-
gr.Markdown("## 🧠 Qwen Chat with
|
| 535 |
|
| 536 |
with gr.Row():
|
| 537 |
with gr.Column(scale=3):
|
|
@@ -567,6 +568,24 @@ with gr.Blocks(title="Qwen GGUF — Chat + RAG (CPU Space)") as demo:
|
|
| 567 |
messages = gr.State([])
|
| 568 |
msg_id = gr.State("")
|
| 569 |
sessions = gr.State([])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 570 |
|
| 571 |
# Events — RAG DB
|
| 572 |
def on_db_change(db_name):
|
|
|
|
| 482 |
else:
|
| 483 |
user_text_aug = user_text
|
| 484 |
|
| 485 |
+
# 4) append user (raw) for UI/persist; use augmented only for model prompt
|
| 486 |
+
visible_messages = messages + [{"role": "user", "content": user_text}]
|
| 487 |
+
prompt_messages = messages + [{"role": "user", "content": user_text_aug}]
|
| 488 |
|
| 489 |
prompt, max_new = render_qwen_trim(
|
| 490 |
+
messages=prompt_messages,
|
| 491 |
model=model,
|
| 492 |
n_ctx=None,
|
| 493 |
add_generation_prompt=True,
|
|
|
|
| 521 |
reply = str(_out).strip()
|
| 522 |
|
| 523 |
# 5) append assistant + persist
|
| 524 |
+
messages = visible_messages + [{"role": "assistant", "content": reply}]
|
| 525 |
|
| 526 |
if msg_id:
|
| 527 |
msg_dir = _as_dir(BASE_MSG_DIR, msg_id)
|
| 528 |
persist_messages(messages, msg_dir, archive_last_turn=True)
|
| 529 |
|
| 530 |
+
return "", messages, visible_chat(messages), msg_id, sessions_update, sessions, gr.update(value=rag_context_text, visible=use_rag)
|
| 531 |
|
| 532 |
|
| 533 |
# ===================== UI =====================
|
| 534 |
+
with gr.Blocks(title="Qwen Chat with RAG (CPU Space)") as demo:
|
| 535 |
+
gr.Markdown("## 🧠 Qwen Chat with RAG (BGEM3 + FAISS)")
|
| 536 |
|
| 537 |
with gr.Row():
|
| 538 |
with gr.Column(scale=3):
|
|
|
|
| 568 |
messages = gr.State([])
|
| 569 |
msg_id = gr.State("")
|
| 570 |
sessions = gr.State([])
|
| 571 |
+
# Toggle visibility of RAG UI when checkbox changes
|
| 572 |
+
def toggle_rag_visibility(use):
|
| 573 |
+
vis = bool(use)
|
| 574 |
+
return (
|
| 575 |
+
gr.update(visible=vis), # db_selector
|
| 576 |
+
gr.update(visible=vis), # top_k
|
| 577 |
+
gr.update(visible=vis), # rerank_take
|
| 578 |
+
gr.update(visible=vis), # rag_status
|
| 579 |
+
gr.update(visible=vis), # file_box
|
| 580 |
+
gr.update(visible=vis), # add_btn
|
| 581 |
+
gr.update(visible=vis), # rag_ctx
|
| 582 |
+
)
|
| 583 |
+
|
| 584 |
+
use_rag.change(
|
| 585 |
+
toggle_rag_visibility,
|
| 586 |
+
inputs=[use_rag],
|
| 587 |
+
outputs=[db_selector, top_k, rerank_take, rag_status, file_box, add_btn, rag_ctx],
|
| 588 |
+
)
|
| 589 |
|
| 590 |
# Events — RAG DB
|
| 591 |
def on_db_change(db_name):
|
requirements.txt
CHANGED
|
@@ -6,4 +6,5 @@ faiss-cpu
|
|
| 6 |
FlagEmbedding
|
| 7 |
sentence-transformers
|
| 8 |
langchain-community
|
| 9 |
-
langchain-text-splitters
|
|
|
|
|
|
| 6 |
FlagEmbedding
|
| 7 |
sentence-transformers
|
| 8 |
langchain-community
|
| 9 |
+
langchain-text-splitters
|
| 10 |
+
pypdf
|