Update app.py
Browse files
app.py
CHANGED
|
@@ -14,12 +14,14 @@ def generate_svg(description):
|
|
| 14 |
Create an SVG diagram for {description} with the following specifications:
|
| 15 |
1. Canvas Setup:
|
| 16 |
- Use viewBox="0 0 800 600"
|
| 17 |
-
|
| 18 |
- Text: centered, with title (14px, bold) and details (12px)
|
|
|
|
|
|
|
| 19 |
- Color scheme: professional color choices
|
| 20 |
- Consistent stroke width: 2px
|
| 21 |
- Avoid line crossings in connections
|
| 22 |
-
|
| 23 |
Put the name of the Diagram in bold on top
|
| 24 |
- Multiple Color coding
|
| 25 |
Please generate a complete SVG code that can be directly used. Ensure the code follows SVG best practices and includes proper spacing and formatting for readability.
|
|
@@ -42,7 +44,7 @@ Generate the correct code, ensure it is free from construct error and this kind
|
|
| 42 |
with open("diagram.svg", "w") as f:
|
| 43 |
f.write(full_svg_code)
|
| 44 |
|
| 45 |
-
# Return
|
| 46 |
return full_svg_code, "diagram.svg", full_svg_code
|
| 47 |
|
| 48 |
def update_svg(modified_svg_code):
|
|
@@ -51,7 +53,9 @@ def update_svg(modified_svg_code):
|
|
| 51 |
f.write(modified_svg_code)
|
| 52 |
return modified_svg_code, "diagram.svg"
|
| 53 |
|
| 54 |
-
with gr.Blocks(
|
|
|
|
|
|
|
| 55 |
gr.Markdown("# Miru - Diagram Viewer")
|
| 56 |
gr.Markdown("Use the **Generate Diagram** tab to create a diagram by describing it. In the **Update Diagram** tab, you can edit the generated SVG code and update the diagram.")
|
| 57 |
|
|
@@ -65,10 +69,9 @@ with gr.Blocks() as demo:
|
|
| 65 |
interactive=True)
|
| 66 |
# Generated SVG displayed in a larger HTML area
|
| 67 |
svg_output = gr.HTML(label="Generated SVG", elem_id="svg-container", value="")
|
| 68 |
-
svg_output.style(height="600px")
|
| 69 |
download_svg_output = gr.File(label="Download SVG")
|
| 70 |
|
| 71 |
-
#
|
| 72 |
description_input.submit(fn=generate_svg,
|
| 73 |
inputs=description_input,
|
| 74 |
outputs=[svg_output, download_svg_output, svg_state])
|
|
@@ -78,7 +81,7 @@ with gr.Blocks() as demo:
|
|
| 78 |
modified_svg_input = gr.Textbox(label="Edit SVG Code", lines=10, interactive=True)
|
| 79 |
load_button = gr.Button("Load Generated Code")
|
| 80 |
update_button = gr.Button("Update Diagram")
|
| 81 |
-
updated_svg_output = gr.HTML(label="Updated SVG", elem_id="svg-container", value="")
|
| 82 |
updated_download_svg_output = gr.File(label="Download SVG")
|
| 83 |
|
| 84 |
# Load the generated SVG code from state into the editable textbox
|
|
@@ -88,4 +91,4 @@ with gr.Blocks() as demo:
|
|
| 88 |
inputs=modified_svg_input,
|
| 89 |
outputs=[updated_svg_output, updated_download_svg_output])
|
| 90 |
|
| 91 |
-
demo.launch()
|
|
|
|
| 14 |
Create an SVG diagram for {description} with the following specifications:
|
| 15 |
1. Canvas Setup:
|
| 16 |
- Use viewBox="0 0 800 600"
|
| 17 |
+
2. Visual Style Requirements (apply when needed):
|
| 18 |
- Text: centered, with title (14px, bold) and details (12px)
|
| 19 |
+
- Ensure consistent spacing
|
| 20 |
+
- Ensure proper use of arrow only when needed
|
| 21 |
- Color scheme: professional color choices
|
| 22 |
- Consistent stroke width: 2px
|
| 23 |
- Avoid line crossings in connections
|
| 24 |
+
3. Additional Requirements:
|
| 25 |
Put the name of the Diagram in bold on top
|
| 26 |
- Multiple Color coding
|
| 27 |
Please generate a complete SVG code that can be directly used. Ensure the code follows SVG best practices and includes proper spacing and formatting for readability.
|
|
|
|
| 44 |
with open("diagram.svg", "w") as f:
|
| 45 |
f.write(full_svg_code)
|
| 46 |
|
| 47 |
+
# Return: HTML for display, file path, and store the full code in state for editing in Tab 2.
|
| 48 |
return full_svg_code, "diagram.svg", full_svg_code
|
| 49 |
|
| 50 |
def update_svg(modified_svg_code):
|
|
|
|
| 53 |
f.write(modified_svg_code)
|
| 54 |
return modified_svg_code, "diagram.svg"
|
| 55 |
|
| 56 |
+
with gr.Blocks(css="""
|
| 57 |
+
|
| 58 |
+
""") as demo:
|
| 59 |
gr.Markdown("# Miru - Diagram Viewer")
|
| 60 |
gr.Markdown("Use the **Generate Diagram** tab to create a diagram by describing it. In the **Update Diagram** tab, you can edit the generated SVG code and update the diagram.")
|
| 61 |
|
|
|
|
| 69 |
interactive=True)
|
| 70 |
# Generated SVG displayed in a larger HTML area
|
| 71 |
svg_output = gr.HTML(label="Generated SVG", elem_id="svg-container", value="")
|
|
|
|
| 72 |
download_svg_output = gr.File(label="Download SVG")
|
| 73 |
|
| 74 |
+
# Submit on pressing Enter in the description box
|
| 75 |
description_input.submit(fn=generate_svg,
|
| 76 |
inputs=description_input,
|
| 77 |
outputs=[svg_output, download_svg_output, svg_state])
|
|
|
|
| 81 |
modified_svg_input = gr.Textbox(label="Edit SVG Code", lines=10, interactive=True)
|
| 82 |
load_button = gr.Button("Load Generated Code")
|
| 83 |
update_button = gr.Button("Update Diagram")
|
| 84 |
+
updated_svg_output = gr.HTML(label="Updated SVG", elem_id="updated-svg-container", value="")
|
| 85 |
updated_download_svg_output = gr.File(label="Download SVG")
|
| 86 |
|
| 87 |
# Load the generated SVG code from state into the editable textbox
|
|
|
|
| 91 |
inputs=modified_svg_input,
|
| 92 |
outputs=[updated_svg_output, updated_download_svg_output])
|
| 93 |
|
| 94 |
+
demo.launch()
|