awacke1's picture
Create app.py
ba59039 verified
raw
history blame
2.86 kB
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()