Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
| 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 |
|