namelessai commited on
Commit
f18daf4
·
verified ·
1 Parent(s): 5d8d25f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -2,6 +2,8 @@ import gradio as gr
2
  import barcode
3
  from barcode.writer import SVGWriter
4
  from io import BytesIO
 
 
5
 
6
  # Barcode explanations
7
  BARCODE_EXPLANATIONS = {
@@ -38,10 +40,12 @@ def generate_barcode_svg(text, barcode_type):
38
  bc = bc_class(text, writer=SVGWriter())
39
  bc.write(svg_buffer)
40
  svg_data = svg_buffer.getvalue().decode("utf-8")
41
- # Save SVG to a file-like object for download
42
- svg_file = BytesIO(svg_data.encode("utf-8"))
43
- svg_file.name = f"{barcode_type}_{text}.svg"
44
- return explanation, svg_data, svg_file
 
 
45
  except Exception as e:
46
  return f"Error: {str(e)}", None, None
47
 
 
2
  import barcode
3
  from barcode.writer import SVGWriter
4
  from io import BytesIO
5
+ import tempfile
6
+ import os
7
 
8
  # Barcode explanations
9
  BARCODE_EXPLANATIONS = {
 
40
  bc = bc_class(text, writer=SVGWriter())
41
  bc.write(svg_buffer)
42
  svg_data = svg_buffer.getvalue().decode("utf-8")
43
+
44
+ # Save SVG to a temporary file and return the file path
45
+ tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".svg")
46
+ tmp.write(svg_data.encode("utf-8"))
47
+ tmp.close()
48
+ return explanation, svg_data, tmp.name
49
  except Exception as e:
50
  return f"Error: {str(e)}", None, None
51