Afeezee commited on
Commit
13fe8be
·
verified ·
1 Parent(s): a7a3f6c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
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
- # Save the SVG code to a file for download
44
- with open("diagram.svg", "w") as f:
45
- f.write(full_svg_code)
46
 
47
- # Return: HTML for display, file path, and store the full code in state for editing in Tab 2.
48
- return full_svg_code, "diagram.svg", 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
- return modified_svg_code, "diagram.svg"
 
 
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