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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -4,6 +4,7 @@ import base64
4
  import gradio as gr
5
  from io import BytesIO
6
  from PIL import Image
 
7
 
8
  def encode_file_to_base64(file_path):
9
  """Reads any file and encodes it to base64."""
@@ -24,9 +25,18 @@ def generate_barcode(data: str, barcode_type: str = "code128"):
24
  # Buka gambar dengan PIL untuk memastikan kompatibilitas dengan Gradio
25
  output.seek(0)
26
  img = Image.open(output)
27
- return img
 
 
 
 
 
 
 
 
 
28
  except Exception as e:
29
- return f"Error: {str(e)}"
30
 
31
  def barcode_interface(input_type, text, file, barcode_type):
32
  if input_type == "Text" and text:
@@ -45,7 +55,7 @@ interface = gr.Interface(
45
  gr.File(label="Upload File"),
46
  gr.Dropdown(["code128", "ean13", "ean8"], label="Barcode Type", value="code128"),
47
  ],
48
- outputs=gr.Image(type="numpy", label="Generated Barcode"),
49
  description="Generate a Barcode from either text or any file.",
50
  css="footer {visibility: hidden}"
51
  )
 
4
  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."""
 
25
  # Buka gambar dengan PIL untuk memastikan kompatibilitas dengan Gradio
26
  output.seek(0)
27
  img = Image.open(output)
28
+
29
+ # Simpan gambar dengan nama file dinamis
30
+ timestamp = datetime.datetime.now().strftime('%Y%m%d_%H%M%S')
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
 
41
  def barcode_interface(input_type, text, file, barcode_type):
42
  if input_type == "Text" and text:
 
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
  )