Update app.py
Browse files
app.py
CHANGED
@@ -2,11 +2,21 @@ import cairosvg
|
|
2 |
import gradio as gr
|
3 |
from PIL import Image
|
4 |
import os
|
|
|
5 |
|
6 |
def show(svg_file):
|
7 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
output_path = "./test.png"
|
9 |
-
cairosvg.svg2png(
|
10 |
|
11 |
# Open and return the PNG image
|
12 |
png_image = Image.open(output_path)
|
|
|
2 |
import gradio as gr
|
3 |
from PIL import Image
|
4 |
import os
|
5 |
+
from io import BytesIO
|
6 |
|
7 |
def show(svg_file):
|
8 |
+
# Check if svg_file is None (no file uploaded)
|
9 |
+
if svg_file is None:
|
10 |
+
return None, None
|
11 |
+
|
12 |
+
# Get the file content from the Gradio file object
|
13 |
+
# svg_file is a tempfile._TemporaryFileWrapper or similar object
|
14 |
+
with open(svg_file.name, 'rb') as f:
|
15 |
+
svg_content = f.read()
|
16 |
+
|
17 |
+
# Convert SVG content to PNG
|
18 |
output_path = "./test.png"
|
19 |
+
cairosvg.svg2png(bytestring=svg_content, write_to=output_path)
|
20 |
|
21 |
# Open and return the PNG image
|
22 |
png_image = Image.open(output_path)
|