import streamlit as st # If you want to render Mermaid diagrams directly in Streamlit, # install streamlit-mermaid: pip install streamlit-mermaid # and then uncomment the following import: # import streamlit_mermaid as st_mermaid # ----------------------------------------------------------------------------------- # Default Mermaid code: a simple AI Architecture diagram with short text + emoji # ----------------------------------------------------------------------------------- DEFAULT_MERMAID = """ flowchart LR %% A short, labeled, emoji-filled flow U((User 😎)) -- "Talk 🗣️" --> LLM[LLM Agent 🤖\\nExtract Info] LLM -- "Query 🔍" --> HS[Hybrid Search 🔎\\nVector+NER+Lexical] HS -- "Reason 🤔" --> RE[Reasoning Engine 🛠️\\nNeuralNetwork+Medical] RE -- "Link 📡" --> KG((Knowledge Graph 📚\\nOntology+GAR+RAG)) """ def main(): st.title("Mermaid Diagram Editor 🏺") # Create two columns: left for Markdown, right for Mermaid left_col, right_col = st.columns(2) # --- Left Column: Markdown Editor --- with left_col: st.subheader("Markdown Side 📝") markdown_text = st.text_area( "Edit Markdown:", value="## Hello!\nYou can type *Markdown* here.\n", height=400 ) # A small button bar at bottom colA, colB = st.columns([1,1]) with colA: if st.button("🔄 Refresh Markdown"): st.write("**Markdown** content refreshed!") with colB: if st.button("❌ Clear Markdown"): markdown_text = "" st.experimental_rerun() # Show the rendered Markdown below st.markdown("---") st.markdown("**Preview:**") st.markdown(markdown_text) # --- Right Column: Mermaid Editor --- with right_col: st.subheader("Mermaid Side 🧜‍♂️") mermaid_code = st.text_area( "Edit Mermaid Code:", value=DEFAULT_MERMAID, height=400 ) # A small button bar at bottom colC, colD = st.columns([1,1]) with colC: if st.button("🎨 Refresh Diagram"): st.write("**Mermaid** diagram refreshed!") with colD: if st.button("❌ Clear Mermaid"): mermaid_code = "" st.experimental_rerun() st.markdown("---") st.markdown("**Mermaid Source:**") st.code(mermaid_code, language="python", line_numbers=True) # If streamlit-mermaid is installed, render the live diagram here: # try: # st_mermaid.mermaid(mermaid_code) # except Exception as e: # st.error("Could not render Mermaid diagram. " + str(e)) if __name__ == "__main__": main()