Adityadn commited on
Commit
2fe855a
·
verified ·
1 Parent(s): 97e1f27

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -5,6 +5,7 @@ import gradio as gr
5
  from io import BytesIO
6
  from PIL import Image
7
  import datetime
 
8
 
9
  def encode_file_to_base64(file_path):
10
  """Reads any file and encodes it to base64."""
@@ -31,10 +32,12 @@ def generate_barcode(data: str, barcode_type: str = "code128"):
31
  file_name = f"flowly_ai_premium_barcode_generator_{timestamp}.png"
32
 
33
  # Simpan file gambar sebagai PNG
34
- img.save(file_name)
 
 
35
 
36
- # Mengembalikan gambar untuk ditampilkan di Gradio dan nama file
37
- return img, file_name
38
  except Exception as e:
39
  return f"Error: {str(e)}", None
40
 
@@ -55,7 +58,7 @@ interface = gr.Interface(
55
  gr.File(label="Upload File"),
56
  gr.Dropdown(["code128", "ean13", "ean8"], label="Barcode Type", value="code128"),
57
  ],
58
- outputs=[gr.Image(type="numpy", label="Generated Barcode"), gr.Download(label="Download Barcode")],
59
  description="Generate a Barcode from either text or any file.",
60
  css="footer {visibility: hidden}"
61
  )
 
5
  from io import BytesIO
6
  from PIL import Image
7
  import datetime
8
+ import os
9
 
10
  def encode_file_to_base64(file_path):
11
  """Reads any file and encodes it to base64."""
 
32
  file_name = f"flowly_ai_premium_barcode_generator_{timestamp}.png"
33
 
34
  # Simpan file gambar sebagai PNG
35
+ file_path = os.path.join("generated_barcodes", file_name)
36
+ os.makedirs(os.path.dirname(file_path), exist_ok=True) # Ensure the directory exists
37
+ img.save(file_path)
38
 
39
+ # Mengembalikan gambar untuk ditampilkan di Gradio dan path file untuk diunduh
40
+ return img, file_path
41
  except Exception as e:
42
  return f"Error: {str(e)}", None
43
 
 
58
  gr.File(label="Upload File"),
59
  gr.Dropdown(["code128", "ean13", "ean8"], label="Barcode Type", value="code128"),
60
  ],
61
+ outputs=[gr.Image(type="numpy", label="Generated Barcode"), gr.File(label="Download Barcode")],
62
  description="Generate a Barcode from either text or any file.",
63
  css="footer {visibility: hidden}"
64
  )