Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import streamlit as st
|
2 |
import openai
|
|
|
3 |
|
4 |
# Function to call OpenAI GPT model for prompt processing
|
5 |
def get_diagram_code(prompt, diagram_type, api_key):
|
@@ -25,7 +26,7 @@ def get_diagram_code(prompt, diagram_type, api_key):
|
|
25 |
|
26 |
# Streamlit App UI
|
27 |
def main():
|
28 |
-
st.title("Generate Diagrams using GPT-4 and
|
29 |
|
30 |
# User input for OpenAI API key
|
31 |
api_key = st.text_input("Enter your OpenAI API Key:", type="password")
|
@@ -49,12 +50,17 @@ def main():
|
|
49 |
# Render Mermaid code to Streamlit
|
50 |
st.code(diagram_code, language='mermaid')
|
51 |
|
52 |
-
#
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
else:
|
60 |
st.error("Failed to generate diagram code.")
|
|
|
1 |
import streamlit as st
|
2 |
import openai
|
3 |
+
import urllib.parse
|
4 |
|
5 |
# Function to call OpenAI GPT model for prompt processing
|
6 |
def get_diagram_code(prompt, diagram_type, api_key):
|
|
|
26 |
|
27 |
# Streamlit App UI
|
28 |
def main():
|
29 |
+
st.title("Generate Diagrams using GPT-4 and MermaidFlow")
|
30 |
|
31 |
# User input for OpenAI API key
|
32 |
api_key = st.text_input("Enter your OpenAI API Key:", type="password")
|
|
|
50 |
# Render Mermaid code to Streamlit
|
51 |
st.code(diagram_code, language='mermaid')
|
52 |
|
53 |
+
# Encode the Mermaid code for use in the MermaidFlow editor URL
|
54 |
+
encoded_code = urllib.parse.quote(diagram_code) # URL encode the Mermaid code
|
55 |
+
|
56 |
+
# MermaidFlow Editor URL with the encoded Mermaid code
|
57 |
+
mermaidflow_url = f"https://www.mermaidflow.app/editor?code={encoded_code}"
|
58 |
+
|
59 |
+
# Embed MermaidFlow Editor in iframe
|
60 |
+
st.markdown(f'<iframe src="{mermaidflow_url}" width="100%" height="600px"></iframe>', unsafe_allow_html=True)
|
61 |
+
|
62 |
+
# Provide a direct link to MermaidFlow editor for convenience
|
63 |
+
st.markdown(f"Click the link to open and edit the diagram directly: [MermaidFlow Editor](https://www.mermaidflow.app/editor?code={encoded_code})")
|
64 |
|
65 |
else:
|
66 |
st.error("Failed to generate diagram code.")
|