Update app.py
Browse files
app.py
CHANGED
|
@@ -58,11 +58,17 @@ def generate_label(data, index):
|
|
| 58 |
c.showPage()
|
| 59 |
c.save()
|
| 60 |
|
| 61 |
-
def
|
| 62 |
"""
|
| 63 |
-
Read
|
| 64 |
"""
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
# Generate labels for each row
|
| 68 |
for i, row in df.iterrows():
|
|
@@ -79,11 +85,11 @@ def process_csv(file):
|
|
| 79 |
|
| 80 |
# Gradio Interface
|
| 81 |
interface = gr.Interface(
|
| 82 |
-
fn=
|
| 83 |
-
inputs=gr.File(label="Upload CSV File"),
|
| 84 |
outputs=gr.File(label="Download Shipping Labels (ZIP)"),
|
| 85 |
title="4x6 Shipping Label Generator",
|
| 86 |
-
description="Upload a
|
| 87 |
)
|
| 88 |
|
| 89 |
# Run the app
|
|
|
|
| 58 |
c.showPage()
|
| 59 |
c.save()
|
| 60 |
|
| 61 |
+
def process_file(file):
|
| 62 |
"""
|
| 63 |
+
Read .csv or .xlsx file and generate labels.
|
| 64 |
"""
|
| 65 |
+
# Determine file format
|
| 66 |
+
if file.name.endswith('.csv'):
|
| 67 |
+
df = pd.read_csv(file.name)
|
| 68 |
+
elif file.name.endswith(('.xls', '.xlsx')):
|
| 69 |
+
df = pd.read_excel(file.name)
|
| 70 |
+
else:
|
| 71 |
+
return "Invalid file format. Please upload a .csv, .xls, or .xlsx file."
|
| 72 |
|
| 73 |
# Generate labels for each row
|
| 74 |
for i, row in df.iterrows():
|
|
|
|
| 85 |
|
| 86 |
# Gradio Interface
|
| 87 |
interface = gr.Interface(
|
| 88 |
+
fn=process_file,
|
| 89 |
+
inputs=gr.File(label="Upload CSV or Excel File"),
|
| 90 |
outputs=gr.File(label="Download Shipping Labels (ZIP)"),
|
| 91 |
title="4x6 Shipping Label Generator",
|
| 92 |
+
description="Upload a .csv or .xlsx file with shipping details, and this app will generate professional 4x6 shipping labels with barcodes.",
|
| 93 |
)
|
| 94 |
|
| 95 |
# Run the app
|