Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -240,25 +240,21 @@ def on_change(inv_type, inv_date, inv_number, modules, audit_type,
|
|
| 240 |
return _preview(inv_type, inv_date, inv_number, modules, audit_type,
|
| 241 |
s_name, s_addr, s_email, s_phone, s_audit_date, unit_override)
|
| 242 |
|
| 243 |
-
def on_generate(uploaded_file, inv_date, inv_num, inv_type, modules, audit_type,
|
| 244 |
-
|
| 245 |
meta, xlsx, pdf = do_generate(
|
| 246 |
-
uploaded_file, inv_type, modules, audit_type, s_audit_date,
|
|
|
|
| 247 |
)
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
# IMPORTANT: stage files into /tmp with safe names so Spaces can serve them
|
| 252 |
-
staged_xlsx = _stage_for_download(xlsx)
|
| 253 |
-
staged_pdf = _stage_for_download(pdf)
|
| 254 |
-
|
| 255 |
return (
|
| 256 |
preview_html,
|
| 257 |
-
gr.
|
| 258 |
-
gr.
|
| 259 |
)
|
| 260 |
|
| 261 |
-
|
| 262 |
def update_audit_dropdown(inv_type_value, current_audit):
|
| 263 |
choices = _choices_for(inv_type_value)
|
| 264 |
value = current_audit if current_audit in choices else choices[0]
|
|
@@ -474,6 +470,8 @@ with gr.Blocks(title="Professional Invoice Generator", css=custom_css) as demo:
|
|
| 474 |
with gr.Group(elem_classes=["upload-section"]):
|
| 475 |
gr.HTML('<div style="text-align: center; margin-bottom: 8px; font-weight: 600; color: #374151; font-size: 11px;">Upload Report</div>')
|
| 476 |
up = gr.File(label="Upload Report (.pdf or .docx)", file_types=[".pdf", ".docx"], file_count="single")
|
|
|
|
|
|
|
| 477 |
gr.HTML('<div style="font-size: 10px; color: #6b7280; text-align: center; margin-top: 4px;">Auto-fill invoice details</div>')
|
| 478 |
|
| 479 |
with gr.Group(elem_classes=["form-controls"]):
|
|
@@ -522,15 +520,18 @@ with gr.Blocks(title="Professional Invoice Generator", css=custom_css) as demo:
|
|
| 522 |
uploaded,
|
| 523 |
inv_t, mods, normalized,
|
| 524 |
out[3], out[4], out[5], out[6], out[7],
|
| 525 |
-
today_str(), "Auto"
|
|
|
|
| 526 |
)
|
| 527 |
|
| 528 |
up.upload(
|
| 529 |
_remember_and_parse,
|
| 530 |
inputs=[up],
|
| 531 |
-
outputs=[uploaded_file, inv_type, modules, audit_type, s_name, s_addr, s_email,
|
|
|
|
| 532 |
api_name=False
|
| 533 |
)
|
|
|
|
| 534 |
|
| 535 |
inv_type.change(
|
| 536 |
update_audit_dropdown,
|
|
|
|
| 240 |
return _preview(inv_type, inv_date, inv_number, modules, audit_type,
|
| 241 |
s_name, s_addr, s_email, s_phone, s_audit_date, unit_override)
|
| 242 |
|
| 243 |
+
def on_generate(uploaded_file, inv_date, inv_num, inv_type, modules, audit_type,
|
| 244 |
+
s_audit_date, s_name, s_addr, s_email, s_phone, unit_override):
|
| 245 |
meta, xlsx, pdf = do_generate(
|
| 246 |
+
uploaded_file, inv_type, modules, audit_type, s_audit_date,
|
| 247 |
+
s_name, s_addr, s_email, s_phone
|
| 248 |
)
|
| 249 |
+
preview_html = _preview(inv_type, inv_date, inv_num, modules, audit_type,
|
| 250 |
+
s_name, s_addr, s_email, s_phone, s_audit_date, unit_override)
|
| 251 |
+
# return updates for the two download buttons
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
return (
|
| 253 |
preview_html,
|
| 254 |
+
gr.update(value=xlsx, visible=bool(xlsx)),
|
| 255 |
+
gr.update(value=pdf, visible=bool(pdf)),
|
| 256 |
)
|
| 257 |
|
|
|
|
| 258 |
def update_audit_dropdown(inv_type_value, current_audit):
|
| 259 |
choices = _choices_for(inv_type_value)
|
| 260 |
value = current_audit if current_audit in choices else choices[0]
|
|
|
|
| 470 |
with gr.Group(elem_classes=["upload-section"]):
|
| 471 |
gr.HTML('<div style="text-align: center; margin-bottom: 8px; font-weight: 600; color: #374151; font-size: 11px;">Upload Report</div>')
|
| 472 |
up = gr.File(label="Upload Report (.pdf or .docx)", file_types=[".pdf", ".docx"], file_count="single")
|
| 473 |
+
# ADD THIS LINE HERE
|
| 474 |
+
file_display = gr.File(label="Selected file", interactive=False, show_download_button=False)
|
| 475 |
gr.HTML('<div style="font-size: 10px; color: #6b7280; text-align: center; margin-top: 4px;">Auto-fill invoice details</div>')
|
| 476 |
|
| 477 |
with gr.Group(elem_classes=["form-controls"]):
|
|
|
|
| 520 |
uploaded,
|
| 521 |
inv_t, mods, normalized,
|
| 522 |
out[3], out[4], out[5], out[6], out[7],
|
| 523 |
+
today_str(), "Auto",
|
| 524 |
+
uploaded
|
| 525 |
)
|
| 526 |
|
| 527 |
up.upload(
|
| 528 |
_remember_and_parse,
|
| 529 |
inputs=[up],
|
| 530 |
+
outputs=[uploaded_file, inv_type, modules, audit_type, s_name, s_addr, s_email,
|
| 531 |
+
s_phone, s_audit_date, inv_date, inv_num, file_display], # + file_display
|
| 532 |
api_name=False
|
| 533 |
)
|
| 534 |
+
|
| 535 |
|
| 536 |
inv_type.change(
|
| 537 |
update_audit_dropdown,
|