Update app.py
Browse files
app.py
CHANGED
@@ -40,18 +40,20 @@ Generate the correct code, ensure it is free from construct error and this kind
|
|
40 |
svg_code = completion.choices[0].message.content.strip()
|
41 |
full_svg_code = f"<svg xmlns='http://www.w3.org/2000/svg' width='100%' height='100%' viewBox='0 0 1000 400'>{svg_code}</svg>"
|
42 |
|
43 |
-
#
|
44 |
-
|
45 |
-
|
46 |
|
47 |
-
# Return
|
48 |
-
return
|
49 |
|
50 |
def update_svg(modified_svg_code):
|
51 |
# Save the modified SVG code to the file
|
52 |
with open("diagram.svg", "w") as f:
|
53 |
f.write(modified_svg_code)
|
54 |
-
|
|
|
|
|
55 |
|
56 |
with gr.Blocks(css="""
|
57 |
|
|
|
40 |
svg_code = completion.choices[0].message.content.strip()
|
41 |
full_svg_code = f"<svg xmlns='http://www.w3.org/2000/svg' width='100%' height='100%' viewBox='0 0 1000 400'>{svg_code}</svg>"
|
42 |
|
43 |
+
# Convert the SVG code to PNG using CairoSVG
|
44 |
+
png_filename = "diagram.png"
|
45 |
+
cairosvg.svg2png(bytestring=full_svg_code.encode('utf-8'), write_to=png_filename)
|
46 |
|
47 |
+
# Return the PNG for display, the PNG file for download, and the SVG code for editing later.
|
48 |
+
return png_filename, png_filename, full_svg_code
|
49 |
|
50 |
def update_svg(modified_svg_code):
|
51 |
# Save the modified SVG code to the file
|
52 |
with open("diagram.svg", "w") as f:
|
53 |
f.write(modified_svg_code)
|
54 |
+
png_filename = "diagram.png"
|
55 |
+
cairosvg.svg2png(bytestring=modified_svg_code.encode('utf-8'), write_to=png_filename)
|
56 |
+
return png_filename, png_filename
|
57 |
|
58 |
with gr.Blocks(css="""
|
59 |
|