Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -132,11 +132,13 @@ def answer_question(question, history):
|
|
| 132 |
if not question.strip():
|
| 133 |
return history, ""
|
| 134 |
if collection.count() == 0:
|
| 135 |
-
history.append(
|
|
|
|
| 136 |
return history, ""
|
| 137 |
chunks = retrieve(question)
|
| 138 |
if not chunks:
|
| 139 |
-
history.append(
|
|
|
|
| 140 |
return history, ""
|
| 141 |
context = "\n\n---\n\n".join(f"[{c['source']}]\n{c['text']}" for c in chunks)
|
| 142 |
system = ("BαΊ‘n lΓ trợ lΓ½ AI. TrαΊ£ lα»i cΓ’u hα»i Dα»°A TRΓN ngα»― cαΊ£nh. "
|
|
@@ -151,7 +153,8 @@ def answer_question(question, history):
|
|
| 151 |
answer = outputs[0]["generated_text"].strip()
|
| 152 |
sources = list({c["source"] for c in chunks})
|
| 153 |
src_text = " \nπ *Nguα»n: " + " Β· ".join(sources) + "*"
|
| 154 |
-
history.append(
|
|
|
|
| 155 |
return history, ""
|
| 156 |
|
| 157 |
def reset_index():
|
|
@@ -322,7 +325,7 @@ SUGS = [
|
|
| 322 |
]
|
| 323 |
|
| 324 |
# ββ UI ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 325 |
-
with gr.Blocks(title="RAG Β· Qwen2.5-0.5B") as demo:
|
| 326 |
|
| 327 |
# ββ Sidebar βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 328 |
with gr.Sidebar(elem_classes="sidebar-content"):
|
|
@@ -356,6 +359,7 @@ with gr.Blocks(title="RAG Β· Qwen2.5-0.5B") as demo:
|
|
| 356 |
height=460,
|
| 357 |
show_label=False,
|
| 358 |
render_markdown=True,
|
|
|
|
| 359 |
)
|
| 360 |
|
| 361 |
with gr.Row(elem_classes="sug-row"):
|
|
@@ -383,4 +387,4 @@ with gr.Blocks(title="RAG Β· Qwen2.5-0.5B") as demo:
|
|
| 383 |
demo.load(fn=get_count, outputs=chunk_vis)
|
| 384 |
|
| 385 |
if __name__ == "__main__":
|
| 386 |
-
demo.launch(
|
|
|
|
| 132 |
if not question.strip():
|
| 133 |
return history, ""
|
| 134 |
if collection.count() == 0:
|
| 135 |
+
history.append({"role": "user", "content": question})
|
| 136 |
+
history.append({"role": "assistant", "content": "β οΈ ChΖ°a cΓ³ tΓ i liα»u. Vui lΓ²ng upload trΖ°α»c."})
|
| 137 |
return history, ""
|
| 138 |
chunks = retrieve(question)
|
| 139 |
if not chunks:
|
| 140 |
+
history.append({"role": "user", "content": question})
|
| 141 |
+
history.append({"role": "assistant", "content": "KhΓ΄ng tΓ¬m thαΊ₯y thΓ΄ng tin liΓͺn quan."})
|
| 142 |
return history, ""
|
| 143 |
context = "\n\n---\n\n".join(f"[{c['source']}]\n{c['text']}" for c in chunks)
|
| 144 |
system = ("BαΊ‘n lΓ trợ lΓ½ AI. TrαΊ£ lα»i cΓ’u hα»i Dα»°A TRΓN ngα»― cαΊ£nh. "
|
|
|
|
| 153 |
answer = outputs[0]["generated_text"].strip()
|
| 154 |
sources = list({c["source"] for c in chunks})
|
| 155 |
src_text = " \nπ *Nguα»n: " + " Β· ".join(sources) + "*"
|
| 156 |
+
history.append({"role": "user", "content": question})
|
| 157 |
+
history.append({"role": "assistant", "content": answer + src_text})
|
| 158 |
return history, ""
|
| 159 |
|
| 160 |
def reset_index():
|
|
|
|
| 325 |
]
|
| 326 |
|
| 327 |
# ββ UI ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 328 |
+
with gr.Blocks(title="RAG Β· Qwen2.5-0.5B", theme=gr.themes.Base(), css=CSS) as demo:
|
| 329 |
|
| 330 |
# ββ Sidebar βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 331 |
with gr.Sidebar(elem_classes="sidebar-content"):
|
|
|
|
| 359 |
height=460,
|
| 360 |
show_label=False,
|
| 361 |
render_markdown=True,
|
| 362 |
+
type="messages",
|
| 363 |
)
|
| 364 |
|
| 365 |
with gr.Row(elem_classes="sug-row"):
|
|
|
|
| 387 |
demo.load(fn=get_count, outputs=chunk_vis)
|
| 388 |
|
| 389 |
if __name__ == "__main__":
|
| 390 |
+
demo.launch(server_name="0.0.0.0", ssr_mode=False)
|