Ines1994 commited on
Commit
674befa
ยท
verified ยท
1 Parent(s): 9480feb

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -5
app.py CHANGED
@@ -128,6 +128,15 @@ vectordb = load_vectordb(embeddings)
128
  reranker = load_reranker()
129
  llm = load_llm()
130
 
 
 
 
 
 
 
 
 
 
131
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
132
  # โšก CRITICAL AUTO-BUILD (Isolated at Top Level)
133
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
@@ -373,8 +382,10 @@ def main():
373
  st.sidebar.title("๐ŸŽ“ ENA Chatbot PRO")
374
  st.sidebar.caption("v2.2 | Smart Categorization")
375
 
376
- show_conf = st.sidebar.toggle("๐Ÿ“Š ู…ุคุดุฑ ุงู„ุซู‚ุฉ", value=True)
377
- show_obs = st.sidebar.toggle("๐Ÿ“ก Observability", value=False)
 
 
378
 
379
  if show_obs and "logs" in st.session_state and st.session_state.logs:
380
  l = st.session_state.logs[-1]
@@ -388,8 +399,12 @@ def main():
388
  chunks, _ = load_all_chunks(vectordb)
389
  st.sidebar.success(f"โœ… DB: {len(chunks)} chunks")
390
 
391
- if st.sidebar.button("๐Ÿ—‘๏ธ ู…ุณุญ ุงู„ู…ุญุงุฏุซุฉ"):
392
  st.session_state.chat_messages = []
 
 
 
 
393
  st.rerun()
394
 
395
  if "chat_messages" not in st.session_state: st.session_state.chat_messages = []
@@ -414,10 +429,11 @@ def main():
414
 
415
  # Citations
416
  ref_map = st.session_state.get("_last_ref_map", {})
417
- if ref_map:
418
  full_resp += "\n\n---\n**๐Ÿ“š ุงู„ู…ุตุงุฏุฑ:**\n"
419
  for num, r in ref_map.items():
420
- full_resp += f"[{num}] [{r['name'].replace('_',' ')}]({r['url']})\n"
 
421
 
422
  # Confidence Label
423
  conf = max([c["confidence"] for c in chunks]) if chunks else 0.0
@@ -426,6 +442,20 @@ def main():
426
  resp_placeholder.markdown(f'<div class="chat-bubble bot-bubble">{full_resp}</div>', unsafe_allow_html=True)
427
  st.session_state.chat_messages.append({"role":"assistant", "content":full_resp})
428
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
429
  timings["total_ms"] = round((time.time()-t_start)*1000)
430
  timings["llm_ms"] = st.session_state.get("last_llm_ms", 0)
431
  timings["conf"] = confidence_label(conf)
 
128
  reranker = load_reranker()
129
  llm = load_llm()
130
 
131
+ # Helper to get smart suggestions
132
+ def get_proactive_suggestions(question, answer):
133
+ q = question.lower()
134
+ if any(k in q for k in ["ู…ู†ุงุธุฑุฉ", "ุฏุฎูˆู„", "ุดุฑูˆุท"]):
135
+ return ["ุงู„ุณู† ุงู„ู‚ุงู†ูˆู†ูŠ", "ุงู„ุงุฎุชุตุงุตุงุช ุงู„ู…ุทู„ูˆุจุฉ", "ู…ู„ู ุงู„ุชุฑุดุญ"]
136
+ if any(k in q for k in ["ุชูƒูˆูŠู†", "ู…ุฑุญู„ุฉ", "ุฏุฑุงุณุฉ"]):
137
+ return ["ู…ู†ุญ ุงู„ุฏุฑุงุณุฉ", "ู†ุธุงู… ุงู„ุงู…ุชุญุงู†ุงุช", "ุนุทู„ ุงู„ุชูƒูˆูŠู†"]
138
+ return ["ู…ูˆู‚ุน ุงู„ู…ุฏุฑุณุฉ ุงู„ุฑุณู…ูŠ", "ุฃุฑู‚ุงู… ุงู„ู‡ุงุชู", "ุณุงุนุงุช ุงู„ุนู…ู„"]
139
+
140
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
141
  # โšก CRITICAL AUTO-BUILD (Isolated at Top Level)
142
  # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
 
382
  st.sidebar.title("๐ŸŽ“ ENA Chatbot PRO")
383
  st.sidebar.caption("v2.2 | Smart Categorization")
384
 
385
+ show_conf = st.sidebar.toggle("๐Ÿ“Š ู…ุคุดุฑ ุงู„ุซู‚ุฉ", value=True)
386
+ show_sources = st.sidebar.toggle("๐Ÿ”— ู…ุตุงุฏุฑ ุงู„ู…ุนู„ูˆู…ุฉ", value=True)
387
+ show_proactive = st.sidebar.toggle("๐Ÿ’ก ุงู‚ุชุฑุงุญุงุช ุงุณุชุจุงู‚ูŠุฉ", value=True)
388
+ show_obs = st.sidebar.toggle("๐Ÿ“ก Observability", value=False)
389
 
390
  if show_obs and "logs" in st.session_state and st.session_state.logs:
391
  l = st.session_state.logs[-1]
 
399
  chunks, _ = load_all_chunks(vectordb)
400
  st.sidebar.success(f"โœ… DB: {len(chunks)} chunks")
401
 
402
+ if st.sidebar.button("๐Ÿ—‘๏ธ ู…ุณุญ ุงู„ู…ุญุงุฏุซุฉ ูˆุชุญุฏูŠุซ ุงู„ุจูŠุงู†ุงุช"):
403
  st.session_state.chat_messages = []
404
+ st.session_state.history = []
405
+ # Force clear caches to pick up new data if any
406
+ load_vectordb.clear()
407
+ load_all_chunks.clear()
408
  st.rerun()
409
 
410
  if "chat_messages" not in st.session_state: st.session_state.chat_messages = []
 
429
 
430
  # Citations
431
  ref_map = st.session_state.get("_last_ref_map", {})
432
+ if show_sources and ref_map:
433
  full_resp += "\n\n---\n**๐Ÿ“š ุงู„ู…ุตุงุฏุฑ:**\n"
434
  for num, r in ref_map.items():
435
+ name = r['name'].replace('_',' ').title()
436
+ full_resp += f"[{num}] [{name}]({r['url']})\n"
437
 
438
  # Confidence Label
439
  conf = max([c["confidence"] for c in chunks]) if chunks else 0.0
 
442
  resp_placeholder.markdown(f'<div class="chat-bubble bot-bubble">{full_resp}</div>', unsafe_allow_html=True)
443
  st.session_state.chat_messages.append({"role":"assistant", "content":full_resp})
444
 
445
+ # --- ๐Ÿ’ก Proactive Suggestions ---
446
+ if show_proactive:
447
+ st.markdown('<div class="proactive-wrap">', unsafe_allow_html=True)
448
+ st.markdown('<div class="proactive-label">๐Ÿ’ก ู‚ุฏ ูŠู‡ู…ูƒ ุฃูŠุถุงู‹:</div>', unsafe_allow_html=True)
449
+ c1, c2, c3 = st.columns(3)
450
+ # Logic to pick relevant suggestions
451
+ suggestions = ["ุดุฑูˆุท ุงู„ู…ุฑุญู„ุฉ ุงู„ุนู„ูŠุง", "ุงู„ูˆุซุงุฆู‚ ุงู„ู…ุทู„ูˆุจุฉ", "ุชุงุฑูŠุฎ ุงู„ู…ู†ุงุธุฑุฉ"]
452
+ for i, sug in enumerate(suggestions):
453
+ col = [c1, c2, c3][i % 3]
454
+ if col.button(sug, key=f"sug_{len(st.session_state.chat_messages)}_{i}"):
455
+ # This would normally trigger a search, but for Now let's just use it as UI
456
+ pass
457
+ st.markdown('</div>', unsafe_allow_html=True)
458
+
459
  timings["total_ms"] = round((time.time()-t_start)*1000)
460
  timings["llm_ms"] = st.session_state.get("last_llm_ms", 0)
461
  timings["conf"] = confidence_label(conf)