HighCWu commited on
Commit
d39079f
·
1 Parent(s): 80b34f1

another way to download svg file.

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -5,6 +5,7 @@ Refer to https://huggingface.co/spaces/dt/ascii-art/blob/main/app.py
5
  import sys, random, argparse
6
  import numpy as np
7
  import math
 
8
  from PIL import Image, ImageFont, ImageDraw
9
  import gradio as gr
10
 
@@ -184,15 +185,18 @@ def sepia(input_img):
184
 
185
  my_image, my_colors = colorizeTextImage(input_img, my_image)
186
  my_html = convertTextToHTML(my_colors, aimg)
187
- with open("result.svg", "w") as f:
188
- f.write(my_html)
 
 
 
189
 
190
- return [my_image, "result.svg", my_html]
191
 
192
 
193
  iface = gr.Interface(sepia,
194
  gr.inputs.Image(),
195
- ["image", "file", "html"],
196
  title = "Colorful ASCII Art",
197
  description = "Convert an image to colorful ASCII art based on ascii character density. Copy and paste the text to a notepad to see it correctly")
198
 
 
5
  import sys, random, argparse
6
  import numpy as np
7
  import math
8
+ import base64
9
  from PIL import Image, ImageFont, ImageDraw
10
  import gradio as gr
11
 
 
185
 
186
  my_image, my_colors = colorizeTextImage(input_img, my_image)
187
  my_html = convertTextToHTML(my_colors, aimg)
188
+ encodedBytes = base64.b64encode(my_html.encode("utf-8"))
189
+ encodedStr = str(encodedBytes, "utf-8")
190
+ my_file_download = r'''
191
+ <a href="data:image/svg+xml;base64,%s" download="result.svg">Click to download result.svg</a>.
192
+ ''' % encodedStr
193
 
194
+ return [my_image, my_file_download, my_html]
195
 
196
 
197
  iface = gr.Interface(sepia,
198
  gr.inputs.Image(),
199
+ ["image", "html", "html"],
200
  title = "Colorful ASCII Art",
201
  description = "Convert an image to colorful ASCII art based on ascii character density. Copy and paste the text to a notepad to see it correctly")
202