awacke1 commited on
Commit
6300d46
·
verified ·
1 Parent(s): 5128b1b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -24
app.py CHANGED
@@ -311,6 +311,7 @@ def FileSidebar():
311
  if st.button('🔍Run'):
312
  st.write("Running GPT logic placeholder...")
313
 
 
314
  # ---------------------------
315
  # Basic Scoring / Glossaries
316
  # ---------------------------
@@ -380,6 +381,7 @@ def display_buttons_with_scores(num_columns_text):
380
  newscore = update_score(key.replace('?',''))
381
  st.markdown(f"Scored **{category} - {game} - {term}** -> {newscore}")
382
 
 
383
  # --------------------
384
  # Image & Video Grids
385
  # --------------------
@@ -472,7 +474,7 @@ def display_content_or_image(query):
472
 
473
 
474
  # ------------------------------------
475
- # MERMAID DIAGRAM with Clickable Links
476
  # ------------------------------------
477
  def generate_mermaid_html(mermaid_code: str) -> str:
478
  """
@@ -517,10 +519,7 @@ def append_model_param(url: str, model_selected: bool) -> str:
517
  return f"{url}{delimiter}model=1"
518
 
519
 
520
- # For demonstration, we add clickable nodes & edges:
521
- # click <nodeId> "<URL>" "_self"
522
- # If you want edges to be clickable, you can label them as well,
523
- # but Mermaid typically only has a 'click' property for nodes.
524
  DEFAULT_MERMAID = """
525
  flowchart LR
526
  %% Notice we have "click LLM ..." lines:
@@ -536,13 +535,8 @@ flowchart LR
536
 
537
  RE -- "Link 📡" --> KG((Knowledge Graph 📚\\nOntology+GAR+RAG))
538
  click KG "/?q=Knowledge%20Graph%20Ontology+GAR+RAG" _self
539
-
540
- %% If you want an "edge click" to pass ?r= something,
541
- %% Mermaid doesn't have direct 'click' for edges,
542
- %% but you can define them as nodes or use linkStyle trick, etc.
543
  """
544
 
545
-
546
  # ---------------------------
547
  # Streamlit Main App
548
  # ---------------------------
@@ -550,7 +544,7 @@ def main():
550
  st.set_page_config(page_title="Mermaid + Clickable Links Demo", layout="wide")
551
 
552
  # 1) Parse query strings on page load
553
- query_params = st.experimental_get_query_params()
554
  current_q = query_params.get("q", [""])[0] # If present, first string
555
  current_r = query_params.get("r", [""])[0]
556
 
@@ -559,30 +553,23 @@ def main():
559
  model_selected = st.sidebar.checkbox("Append ?model=1 to each link?")
560
 
561
  # 3) Generate a dynamic Mermaid code, appending model param if user wants
562
- # We'll do a simple string replace to incorporate the model param
563
- # For a robust approach, parse each URL carefully, then reassemble.
564
  base_diagram = DEFAULT_MERMAID
565
  lines = base_diagram.strip().split("\n")
566
  new_lines = []
567
  for line in lines:
568
  if "click " in line and '"/?' in line:
569
  # e.g. click LLM "/?q=LLM%20Agent" _self
570
- # let's isolate the URL part
571
  parts = re.split(r'click\s+\S+\s+"([^"]+)"\s+("_self")', line)
572
  if len(parts) == 4:
573
- # parts[0] = 'click LLM '
574
- # parts[1] = '/?q=LLM%20Agent%20Extract%20Info'
575
- # parts[2] = ' _self'
576
- # parts[3] = '' (trailing possibly)
577
  url = parts[1]
578
  updated_url = append_model_param(url, model_selected)
579
- # Recombine
580
  new_line = f"{parts[0]}\"{updated_url}\" {parts[2]}"
581
  new_lines.append(new_line)
582
  else:
583
  new_lines.append(line)
584
  else:
585
  new_lines.append(line)
 
586
  mermaid_code = "\n".join(new_lines)
587
 
588
  # 4) Render the top-centered Mermaid diagram
@@ -590,7 +577,7 @@ def main():
590
  diagram_html = generate_mermaid_html(mermaid_code)
591
  components.html(diagram_html, height=400, scrolling=True)
592
 
593
- # 5) Show what the inbound ?q / ?r was
594
  if current_q:
595
  st.markdown(f"**Detected Query**: `?q={current_q}`")
596
  display_content_or_image(current_q)
@@ -623,7 +610,7 @@ def main():
623
  st.session_state["markdown_text"] = ""
624
  st.experimental_rerun()
625
 
626
- # Display
627
  st.markdown("---")
628
  st.markdown("**Preview:**")
629
  st.markdown(markdown_text)
@@ -640,10 +627,11 @@ def main():
640
  value=st.session_state["current_mermaid"],
641
  height=300
642
  )
 
 
643
  colC, colD = st.columns(2)
644
  with colC:
645
  if st.button("🎨 Refresh Diagram"):
646
- # Rebuild the diagram
647
  st.session_state["current_mermaid"] = mermaid_input
648
  st.write("**Mermaid** diagram refreshed! 🌈")
649
  st.experimental_rerun()
@@ -656,7 +644,7 @@ def main():
656
  st.markdown("**Mermaid Source:**")
657
  st.code(mermaid_input, language="python", line_numbers=True)
658
 
659
- # 7) Show Sliders & image/video galleries
660
  st.markdown("---")
661
  st.header("Media Galleries")
662
 
@@ -674,7 +662,7 @@ def main():
674
  display_buttons_with_scores(num_columns_text)
675
  st.markdown("Extended text interface is on...")
676
 
677
- # 9) Render the file sidebar
678
  FileSidebar()
679
 
680
  # 10) Random Title at bottom
 
311
  if st.button('🔍Run'):
312
  st.write("Running GPT logic placeholder...")
313
 
314
+
315
  # ---------------------------
316
  # Basic Scoring / Glossaries
317
  # ---------------------------
 
381
  newscore = update_score(key.replace('?',''))
382
  st.markdown(f"Scored **{category} - {game} - {term}** -> {newscore}")
383
 
384
+
385
  # --------------------
386
  # Image & Video Grids
387
  # --------------------
 
474
 
475
 
476
  # ------------------------------------
477
+ # MERMAID DIAGRAM with Clickable Nodes
478
  # ------------------------------------
479
  def generate_mermaid_html(mermaid_code: str) -> str:
480
  """
 
519
  return f"{url}{delimiter}model=1"
520
 
521
 
522
+ # Default Mermaid diagram with "click" lines
 
 
 
523
  DEFAULT_MERMAID = """
524
  flowchart LR
525
  %% Notice we have "click LLM ..." lines:
 
535
 
536
  RE -- "Link 📡" --> KG((Knowledge Graph 📚\\nOntology+GAR+RAG))
537
  click KG "/?q=Knowledge%20Graph%20Ontology+GAR+RAG" _self
 
 
 
 
538
  """
539
 
 
540
  # ---------------------------
541
  # Streamlit Main App
542
  # ---------------------------
 
544
  st.set_page_config(page_title="Mermaid + Clickable Links Demo", layout="wide")
545
 
546
  # 1) Parse query strings on page load
547
+ query_params = st.experimental_get_query_params() # original usage
548
  current_q = query_params.get("q", [""])[0] # If present, first string
549
  current_r = query_params.get("r", [""])[0]
550
 
 
553
  model_selected = st.sidebar.checkbox("Append ?model=1 to each link?")
554
 
555
  # 3) Generate a dynamic Mermaid code, appending model param if user wants
 
 
556
  base_diagram = DEFAULT_MERMAID
557
  lines = base_diagram.strip().split("\n")
558
  new_lines = []
559
  for line in lines:
560
  if "click " in line and '"/?' in line:
561
  # e.g. click LLM "/?q=LLM%20Agent" _self
 
562
  parts = re.split(r'click\s+\S+\s+"([^"]+)"\s+("_self")', line)
563
  if len(parts) == 4:
 
 
 
 
564
  url = parts[1]
565
  updated_url = append_model_param(url, model_selected)
 
566
  new_line = f"{parts[0]}\"{updated_url}\" {parts[2]}"
567
  new_lines.append(new_line)
568
  else:
569
  new_lines.append(line)
570
  else:
571
  new_lines.append(line)
572
+
573
  mermaid_code = "\n".join(new_lines)
574
 
575
  # 4) Render the top-centered Mermaid diagram
 
577
  diagram_html = generate_mermaid_html(mermaid_code)
578
  components.html(diagram_html, height=400, scrolling=True)
579
 
580
+ # 5) Show inbound ?q / ?r
581
  if current_q:
582
  st.markdown(f"**Detected Query**: `?q={current_q}`")
583
  display_content_or_image(current_q)
 
610
  st.session_state["markdown_text"] = ""
611
  st.experimental_rerun()
612
 
613
+ # Show the rendered Markdown below
614
  st.markdown("---")
615
  st.markdown("**Preview:**")
616
  st.markdown(markdown_text)
 
627
  value=st.session_state["current_mermaid"],
628
  height=300
629
  )
630
+
631
+ # A small button bar
632
  colC, colD = st.columns(2)
633
  with colC:
634
  if st.button("🎨 Refresh Diagram"):
 
635
  st.session_state["current_mermaid"] = mermaid_input
636
  st.write("**Mermaid** diagram refreshed! 🌈")
637
  st.experimental_rerun()
 
644
  st.markdown("**Mermaid Source:**")
645
  st.code(mermaid_input, language="python", line_numbers=True)
646
 
647
+ # 7) Sliders & image/video galleries
648
  st.markdown("---")
649
  st.header("Media Galleries")
650
 
 
662
  display_buttons_with_scores(num_columns_text)
663
  st.markdown("Extended text interface is on...")
664
 
665
+ # 9) File Sidebar
666
  FileSidebar()
667
 
668
  # 10) Random Title at bottom