Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
|
@@ -377,12 +377,19 @@ def run_process(file, question, model_choice, temperature, top_p, external_api_u
|
|
| 377 |
def on_export_excel(parsed_obj):
|
| 378 |
try:
|
| 379 |
if not parsed_obj:
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 383 |
except Exception as e:
|
| 384 |
print(f"Export error: {e}")
|
| 385 |
-
return None
|
| 386 |
|
| 387 |
def clear_all():
|
| 388 |
# file, preview, output_text, question, model, parsed_state, download,
|
|
@@ -475,7 +482,7 @@ def main():
|
|
| 475 |
output_text = gr.Code(label="LLM Message", language="json", elem_id="llm-output")
|
| 476 |
with gr.Row():
|
| 477 |
export_btn = gr.Button("⬇️ Export to Excel", elem_classes=["secondary-button"])
|
| 478 |
-
download_file = gr.File(label="Download Excel", interactive=False)
|
| 479 |
|
| 480 |
# Events
|
| 481 |
file.change(preview_process, inputs=[file], outputs=[preview])
|
|
|
|
| 377 |
def on_export_excel(parsed_obj):
|
| 378 |
try:
|
| 379 |
if not parsed_obj:
|
| 380 |
+
# không có JSON để export → giữ nguyên, không hiện nút tải
|
| 381 |
+
return gr.update(value=None, visible=False)
|
| 382 |
+
|
| 383 |
+
# tạo file an toàn, giữ lại sau khi request kết thúc
|
| 384 |
+
fd, tmp_path = tempfile.mkstemp(suffix=".xlsx")
|
| 385 |
+
os.close(fd)
|
| 386 |
+
_to_excel_generic(parsed_obj, tmp_path)
|
| 387 |
+
|
| 388 |
+
# trả về path và bật visible để hiện link download
|
| 389 |
+
return gr.update(value=tmp_path, visible=True)
|
| 390 |
except Exception as e:
|
| 391 |
print(f"Export error: {e}")
|
| 392 |
+
return gr.update(value=None, visible=False)
|
| 393 |
|
| 394 |
def clear_all():
|
| 395 |
# file, preview, output_text, question, model, parsed_state, download,
|
|
|
|
| 482 |
output_text = gr.Code(label="LLM Message", language="json", elem_id="llm-output")
|
| 483 |
with gr.Row():
|
| 484 |
export_btn = gr.Button("⬇️ Export to Excel", elem_classes=["secondary-button"])
|
| 485 |
+
download_file = gr.File(label="Download Excel", interactive=False, visible=False)
|
| 486 |
|
| 487 |
# Events
|
| 488 |
file.change(preview_process, inputs=[file], outputs=[preview])
|