Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,34 @@
|
|
1 |
import cairosvg
|
2 |
import gradio as gr
|
|
|
|
|
3 |
|
4 |
-
def show(
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
with gr.Blocks() as bl:
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
bl.launch()
|
|
|
1 |
import cairosvg
|
2 |
import gradio as gr
|
3 |
+
from PIL import Image
|
4 |
+
import os
|
5 |
|
6 |
+
def show(svg_input):
|
7 |
+
# Convert SVG to PNG
|
8 |
+
output_path = "./test.png"
|
9 |
+
cairosvg.svg2png(bytestring=svg_input.encode('utf-8'), write_to=output_path)
|
10 |
+
|
11 |
+
# Open and return the PNG image
|
12 |
+
png_image = Image.open(output_path)
|
13 |
+
return png_image, output_path
|
14 |
|
15 |
with gr.Blocks() as bl:
|
16 |
+
gr.Markdown("# SVG to PNG Converter")
|
17 |
+
|
18 |
+
with gr.Row():
|
19 |
+
with gr.Column():
|
20 |
+
svg_input = gr.Textbox(label="SVG URL or Code", placeholder="Enter SVG URL or paste SVG code here")
|
21 |
+
convert_btn = gr.Button("Convert")
|
22 |
+
|
23 |
+
with gr.Column():
|
24 |
+
png_output = gr.Image(type='pil', label="Converted PNG")
|
25 |
+
download_btn = gr.File(label="Download PNG")
|
26 |
+
|
27 |
+
# Connect the conversion function
|
28 |
+
convert_btn.click(
|
29 |
+
fn=show,
|
30 |
+
inputs=svg_input,
|
31 |
+
outputs=[png_output, download_btn]
|
32 |
+
)
|
33 |
|
34 |
bl.launch()
|