Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
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() | |