gtech13 commited on
Commit
932b263
Β·
verified Β·
1 Parent(s): b79d0d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -12
app.py CHANGED
@@ -26,7 +26,17 @@ warnings.filterwarnings("ignore")
26
  # ==========================================
27
  # 1. PAGE CONFIGURATION & MAPPINGS
28
  # ==========================================
29
- st.set_page_config(page_title="Topic Modeling Pipeline", layout="wide", initial_sidebar_state="collapsed")
 
 
 
 
 
 
 
 
 
 
30
 
31
  EMBEDDING_MAP = {
32
  "MiniLM (Fast & Lightweight)": "sentence-transformers/all-MiniLM-L6-v2",
@@ -305,7 +315,11 @@ if st.button("πŸš€ Run Topic Modeling Pipeline", type="primary", use_container_w
305
  with st.spinner("Rendering Mathematical Dashboard..."):
306
  sns.set_theme(style="whitegrid")
307
  fig = plt.figure(figsize=(18, 16))
308
- fig.suptitle(f"Topic Modeling Mathematical Pipeline\n(Pooling: {ui_pooling.split()[0]} | Rep: {ui_extraction.split()[0]})", fontsize=20, fontweight='bold', y=0.98)
 
 
 
 
309
 
310
  # Style for the Math/Data boxes
311
  box_style = dict(boxstyle="round,pad=0.5", facecolor='#f8f9fa', edgecolor='#4b72b8', alpha=0.95, lw=2)
@@ -372,12 +386,16 @@ if st.button("πŸš€ Run Topic Modeling Pipeline", type="primary", use_container_w
372
  # 4. Representation
373
  # --------------------------------------------------
374
  ax4 = plt.subplot(3, 2, 4)
375
- theme_1_data = topic_model.get_topic(0)
 
 
 
 
376
  if theme_1_data:
377
  words = [x[0] for x in theme_1_data][::-1]
378
  scores = [x[1] for x in theme_1_data][::-1]
379
  ax4.barh(words, scores, color='coral', edgecolor='black')
380
- ax4.set_title(f"STEP 4: Topic Representation ({ui_extraction.split()[0]})", fontsize=13, fontweight='bold')
381
 
382
  # Live Data Extraction
383
  top_word_score = round(scores[-1], 4)
@@ -392,12 +410,12 @@ if st.button("πŸš€ Run Topic Modeling Pipeline", type="primary", use_container_w
392
  else:
393
  ax4.text(0.5, 0.5, "Theme not found", ha='center', transform=ax4.transAxes)
394
 
395
- # --------------------------------------------------
396
- # 5. KPI Dashboard (Formulas & Live Calculations)
397
  # --------------------------------------------------
398
  ax5 = plt.subplot(3, 2, 5)
399
  ax5.axis('off')
400
- ax5.set_title("STEP 5: Post-Hoc Evaluation (Math & Live Data)", fontsize=13, fontweight='bold', y=0.9)
401
 
402
  # Get the actual distance metric used for the label
403
  dist_used = ui_metric if algo_used == "UMAP" else "euclidean"
@@ -413,9 +431,9 @@ if st.button("πŸš€ Run Topic Modeling Pipeline", type="primary", use_container_w
413
  f"Live Calc: Score = {npmi_status} across {len(all_words)} valid themes"
414
  )
415
 
416
- ax5.text(0.5, 0.4, kpi_math, fontsize=11, va='center', ha='center',
417
  bbox=dict(boxstyle="square,pad=1.5", facecolor='#e6f2ff', edgecolor='#377eb8', lw=2))
418
-
419
  # --------------------------------------------------
420
  # 6. Summary Matrix Transformations
421
  # --------------------------------------------------
@@ -427,7 +445,7 @@ if st.button("πŸš€ Run Topic Modeling Pipeline", type="primary", use_container_w
427
  f"2. {emb_shape} $\\rightarrow$ {red_shape} Matrix (Geometric Compression)\n"
428
  f"3. {red_shape} $\\rightarrow$ ({len(topics)},) Array (Discrete Bucketing)\n"
429
  f"4. ({len(topics)},) $\\rightarrow$ c-TF-IDF Matrix (Word Extraction)\n"
430
- f"5. c-TF-IDF $\\rightarrow$ {CONFIG['words_per_theme']} Output Words (Per Theme)\n\n"
431
  "This proves Topic Modeling is a sequence of \ndimensionality reductions and matrix multiplications."
432
  )
433
  ax6.text(0.1, 0.5, summary_text, fontsize=12, va='center', ha='left',
@@ -435,5 +453,3 @@ if st.button("πŸš€ Run Topic Modeling Pipeline", type="primary", use_container_w
435
 
436
  plt.subplots_adjust(hspace=0.7, wspace=0.3)
437
  st.pyplot(fig, use_container_width=True)
438
-
439
-
 
26
  # ==========================================
27
  # 1. PAGE CONFIGURATION & MAPPINGS
28
  # ==========================================
29
+ st.set_page_config(page_title="Topic Modeling Pipeline", layout="wide", initial_sidebar_state="expanded")
30
+
31
+ # Add this right below set_page_config to stop the screen from jumping left/right
32
+ st.markdown("""
33
+ <style>
34
+ /* Force the vertical scrollbar to always show so the page width never changes */
35
+ html { overflow-y: scroll; }
36
+ /* Prevent horizontal scrolling */
37
+ .block-container { max-width: 100%; overflow-x: hidden; }
38
+ </style>
39
+ """, unsafe_allow_html=True)
40
 
41
  EMBEDDING_MAP = {
42
  "MiniLM (Fast & Lightweight)": "sentence-transformers/all-MiniLM-L6-v2",
 
315
  with st.spinner("Rendering Mathematical Dashboard..."):
316
  sns.set_theme(style="whitegrid")
317
  fig = plt.figure(figsize=(18, 16))
318
+
319
+ # Safe extraction for the title
320
+ pool_title = ui_pooling.split()[0]
321
+ rep_title = ui_extraction.split()[0]
322
+ fig.suptitle(f"Topic Modeling Mathematical Pipeline\n(Pooling: {pool_title} | Rep: {rep_title})", fontsize=20, fontweight='bold', y=0.98)
323
 
324
  # Style for the Math/Data boxes
325
  box_style = dict(boxstyle="round,pad=0.5", facecolor='#f8f9fa', edgecolor='#4b72b8', alpha=0.95, lw=2)
 
386
  # 4. Representation
387
  # --------------------------------------------------
388
  ax4 = plt.subplot(3, 2, 4)
389
+
390
+ # Safely grab the first valid topic found
391
+ valid_topics = [t for t in topic_model.get_topics().keys() if t != -1]
392
+ theme_1_data = topic_model.get_topic(valid_topics[0]) if valid_topics else None
393
+
394
  if theme_1_data:
395
  words = [x[0] for x in theme_1_data][::-1]
396
  scores = [x[1] for x in theme_1_data][::-1]
397
  ax4.barh(words, scores, color='coral', edgecolor='black')
398
+ ax4.set_title(f"STEP 4: Topic Representation ({rep_title})", fontsize=13, fontweight='bold')
399
 
400
  # Live Data Extraction
401
  top_word_score = round(scores[-1], 4)
 
410
  else:
411
  ax4.text(0.5, 0.5, "Theme not found", ha='center', transform=ax4.transAxes)
412
 
413
+ # --------------------------------------------------
414
+ # 5. KPI Dashboard
415
  # --------------------------------------------------
416
  ax5 = plt.subplot(3, 2, 5)
417
  ax5.axis('off')
418
+ ax5.set_title("STEP 5: Post-Hoc Evaluation Formulas", fontsize=13, fontweight='bold', y=0.9)
419
 
420
  # Get the actual distance metric used for the label
421
  dist_used = ui_metric if algo_used == "UMAP" else "euclidean"
 
431
  f"Live Calc: Score = {npmi_status} across {len(all_words)} valid themes"
432
  )
433
 
434
+ ax5.text(0.5, 0.4, kpi_math, fontsize=12, va='center', ha='center',
435
  bbox=dict(boxstyle="square,pad=1.5", facecolor='#e6f2ff', edgecolor='#377eb8', lw=2))
436
+
437
  # --------------------------------------------------
438
  # 6. Summary Matrix Transformations
439
  # --------------------------------------------------
 
445
  f"2. {emb_shape} $\\rightarrow$ {red_shape} Matrix (Geometric Compression)\n"
446
  f"3. {red_shape} $\\rightarrow$ ({len(topics)},) Array (Discrete Bucketing)\n"
447
  f"4. ({len(topics)},) $\\rightarrow$ c-TF-IDF Matrix (Word Extraction)\n"
448
+ f"5. c-TF-IDF $\\rightarrow$ {words_per_theme} Output Words (Per Theme)\n\n" # THE BUG FIX!
449
  "This proves Topic Modeling is a sequence of \ndimensionality reductions and matrix multiplications."
450
  )
451
  ax6.text(0.1, 0.5, summary_text, fontsize=12, va='center', ha='left',
 
453
 
454
  plt.subplots_adjust(hspace=0.7, wspace=0.3)
455
  st.pyplot(fig, use_container_width=True)