Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
def svg_to_html(svg_file):
|
4 |
# Read the SVG file content
|
@@ -21,17 +22,37 @@ def svg_to_html(svg_file):
|
|
21 |
"""
|
22 |
return html_content, svg_code
|
23 |
|
24 |
-
# Define the Gradio interface
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
gr.
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
# Launch the interface
|
37 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import base64
|
3 |
|
4 |
def svg_to_html(svg_file):
|
5 |
# Read the SVG file content
|
|
|
22 |
"""
|
23 |
return html_content, svg_code
|
24 |
|
25 |
+
# Define the Gradio interface with tabs
|
26 |
+
with gr.Blocks() as iface:
|
27 |
+
gr.Markdown("# SVG to HTML Converter")
|
28 |
+
gr.Markdown("Upload an SVG file to see the generated HTML code and a preview of the SVG.")
|
29 |
+
|
30 |
+
with gr.Tabs():
|
31 |
+
with gr.TabItem("Upload SVG"):
|
32 |
+
svg_file = gr.File(label="Upload SVG File")
|
33 |
+
submit_button = gr.Button("Submit")
|
34 |
+
|
35 |
+
with gr.TabItem("Generated HTML"):
|
36 |
+
html_output = gr.Textbox(lines=15, label="Generated HTML")
|
37 |
+
|
38 |
+
with gr.TabItem("SVG Preview"):
|
39 |
+
svg_preview = gr.HTML(label="SVG Preview")
|
40 |
+
html_link = gr.HTML(label="HTML Code Link")
|
41 |
+
|
42 |
+
# Define the function to be called when the button is clicked
|
43 |
+
def on_submit(svg_file):
|
44 |
+
html_content, svg_code = svg_to_html(svg_file)
|
45 |
+
# Create a data URL for the HTML content
|
46 |
+
html_data_url = f"data:text/html;charset=utf-8,{base64.b64encode(html_content.encode()).decode()}"
|
47 |
+
# Create an HTML link to open the HTML content in a new tab
|
48 |
+
link_html = f'<a href="{html_data_url}" target="_blank">Open HTML in New Tab</a>'
|
49 |
+
return html_content, f'<div style="text-align: center;">{svg_code}</div>', link_html
|
50 |
+
|
51 |
+
submit_button.click(
|
52 |
+
fn=on_submit,
|
53 |
+
inputs=svg_file,
|
54 |
+
outputs=[html_output, svg_preview, html_link]
|
55 |
+
)
|
56 |
|
57 |
# Launch the interface
|
58 |
iface.launch()
|