Tiens0710 commited on
Commit
78066c1
Β·
verified Β·
1 Parent(s): af4565a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
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([question, "⚠️ ChΖ°a cΓ³ tΓ i liệu. Vui lΓ²ng upload trΖ°α»›c."])
 
136
  return history, ""
137
  chunks = retrieve(question)
138
  if not chunks:
139
- history.append([question, "KhΓ΄ng tΓ¬m thαΊ₯y thΓ΄ng tin liΓͺn quan."])
 
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([question, answer + src_text])
 
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(css=CSS, theme=gr.themes.Base(), server_name="0.0.0.0", ssr_mode=False)
 
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)