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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -38,12 +38,15 @@ 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
- return explanation, svg_data
 
 
 
42
  except Exception as e:
43
- return f"Error: {str(e)}", None
44
 
45
  with gr.Blocks() as demo:
46
- gr.Markdown("# Barcode Generator (SVG Output)")
47
  with gr.Row():
48
  text_input = gr.Textbox(label="Text to encode")
49
  barcode_type = gr.Dropdown(
@@ -53,11 +56,12 @@ with gr.Blocks() as demo:
53
  )
54
  explanation_box = gr.Markdown(label="Barcode Explanation")
55
  svg_output = gr.HTML(label="Generated Barcode (SVG)")
 
56
  btn = gr.Button("Generate Barcode")
57
  btn.click(
58
  generate_barcode_svg,
59
  inputs=[text_input, barcode_type],
60
- outputs=[explanation_box, svg_output]
61
  )
62
 
63
  demo.launch()
 
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
 
48
  with gr.Blocks() as demo:
49
+ gr.Markdown("# Barcode Generator (SVG Output with Download)")
50
  with gr.Row():
51
  text_input = gr.Textbox(label="Text to encode")
52
  barcode_type = gr.Dropdown(
 
56
  )
57
  explanation_box = gr.Markdown(label="Barcode Explanation")
58
  svg_output = gr.HTML(label="Generated Barcode (SVG)")
59
+ download_btn = gr.File(label="Download SVG")
60
  btn = gr.Button("Generate Barcode")
61
  btn.click(
62
  generate_barcode_svg,
63
  inputs=[text_input, barcode_type],
64
+ outputs=[explanation_box, svg_output, download_btn]
65
  )
66
 
67
  demo.launch()