codelion commited on
Commit
a8aa56e
·
verified ·
1 Parent(s): d92b783

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -4
app.py CHANGED
@@ -1,11 +1,34 @@
1
  import cairosvg
2
  import gradio as gr
 
 
3
 
4
- def show(url):
5
- cairosvg.svg2png(url=url, write_to=f"./test.png")
 
 
 
 
 
 
6
 
7
  with gr.Blocks() as bl:
8
- img = gr.Image(type='pil')
9
- img.upload(fn=show, inputs=img)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()