Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -353,39 +353,16 @@ class AIEvaluationForm:
|
|
| 353 |
label="Scorecard JSON",
|
| 354 |
show_label=True
|
| 355 |
)
|
| 356 |
-
# Enhanced download section with better visibility
|
| 357 |
-
with gr.Group():
|
| 358 |
-
gr.Markdown("### 💾 Download Your Scorecard")
|
| 359 |
-
|
| 360 |
-
with gr.Row():
|
| 361 |
-
# Status text to show download readiness
|
| 362 |
-
download_status = gr.Markdown(
|
| 363 |
-
"ℹ️ *Generate a scorecard to enable download*",
|
| 364 |
-
visible=True
|
| 365 |
-
)
|
| 366 |
-
|
| 367 |
-
with gr.Row():
|
| 368 |
-
# Large prominent download button
|
| 369 |
-
download_btn = gr.Button(
|
| 370 |
-
"📥 Download Scorecard JSON",
|
| 371 |
-
variant="primary",
|
| 372 |
-
size="lg",
|
| 373 |
-
visible=False,
|
| 374 |
-
scale=2
|
| 375 |
-
)
|
| 376 |
-
|
| 377 |
-
# Alternative: HTML download link (more direct)
|
| 378 |
-
download_html = gr.HTML(
|
| 379 |
-
"",
|
| 380 |
-
visible=False
|
| 381 |
-
)
|
| 382 |
|
| 383 |
-
|
| 384 |
download_file = gr.File(
|
| 385 |
-
label="Download
|
| 386 |
-
visible=False
|
|
|
|
|
|
|
|
|
|
| 387 |
)
|
| 388 |
-
|
| 389 |
# Event handlers
|
| 390 |
all_inputs = system_inputs + eval_inputs
|
| 391 |
|
|
@@ -403,111 +380,11 @@ class AIEvaluationForm:
|
|
| 403 |
with open(filename, 'w') as f:
|
| 404 |
f.write(json_content)
|
| 405 |
|
| 406 |
-
# Create HTML download link
|
| 407 |
-
download_link_html = f"""
|
| 408 |
-
<div style="text-align: center; padding: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border-radius: 15px; margin: 10px 0;">
|
| 409 |
-
<a href="data:application/json;charset=utf-8,{json.dumps(scorecard, indent=2).replace('"', '"')}"
|
| 410 |
-
download="{filename}"
|
| 411 |
-
style="display: inline-block; padding: 15px 30px; background: white; color: #333; text-decoration: none; border-radius: 10px; font-weight: bold; font-size: 18px; box-shadow: 0 4px 15px rgba(0,0,0,0.2); transition: transform 0.2s;"
|
| 412 |
-
onmouseover="this.style.transform='scale(1.05)'"
|
| 413 |
-
onmouseout="this.style.transform='scale(1)'">
|
| 414 |
-
📥 Download {filename}
|
| 415 |
-
</a>
|
| 416 |
-
<div style="color: white; margin-top: 10px; font-size: 14px;">
|
| 417 |
-
Right-click and "Save As" if the download doesn't start automatically
|
| 418 |
-
</div>
|
| 419 |
-
</div>
|
| 420 |
-
"""
|
| 421 |
-
|
| 422 |
return (
|
| 423 |
scorecard, # JSON display
|
| 424 |
-
gr.
|
| 425 |
-
gr.File(value=filename, visible=True, label=f"📥 {filename} - Click to Download") # Download file
|
| 426 |
)
|
| 427 |
|
| 428 |
-
|
| 429 |
-
# Alternative approach: Use a more prominent file display
|
| 430 |
-
def generate_with_prominent_file(*args):
|
| 431 |
-
"""Alternative version with more prominent file component"""
|
| 432 |
-
progress(0.3, desc="Processing inputs...")
|
| 433 |
-
scorecard, filename = self.generate_scorecard(*args)
|
| 434 |
-
|
| 435 |
-
progress(0.7, desc="Generating JSON...")
|
| 436 |
-
json_content = json.dumps(scorecard, indent=2)
|
| 437 |
-
|
| 438 |
-
progress(1.0, desc="Complete!")
|
| 439 |
-
|
| 440 |
-
# Save to temporary file for download
|
| 441 |
-
with open(filename, 'w') as f:
|
| 442 |
-
f.write(json_content)
|
| 443 |
-
|
| 444 |
-
return (
|
| 445 |
-
scorecard, # JSON display
|
| 446 |
-
gr.File(
|
| 447 |
-
value=filename,
|
| 448 |
-
visible=True,
|
| 449 |
-
label=f"📥 Your Scorecard is Ready! Click to Download: {filename}",
|
| 450 |
-
show_label=True,
|
| 451 |
-
elem_id="download-file-prominent"
|
| 452 |
-
),
|
| 453 |
-
)
|
| 454 |
-
|
| 455 |
-
# Additional CSS for better file download styling (add to your existing CSS)
|
| 456 |
-
additional_css = """
|
| 457 |
-
/* Enhanced download styling */
|
| 458 |
-
#download-file-prominent {
|
| 459 |
-
border: 3px dashed #4CAF50 !important;
|
| 460 |
-
border-radius: 15px !important;
|
| 461 |
-
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%) !important;
|
| 462 |
-
padding: 20px !important;
|
| 463 |
-
margin: 20px 0 !important;
|
| 464 |
-
}
|
| 465 |
-
|
| 466 |
-
#download-file-prominent .file-preview {
|
| 467 |
-
background: white !important;
|
| 468 |
-
border-radius: 10px !important;
|
| 469 |
-
padding: 15px !important;
|
| 470 |
-
box-shadow: 0 4px 15px rgba(0,0,0,0.1) !important;
|
| 471 |
-
}
|
| 472 |
-
|
| 473 |
-
#download-file-prominent .file-name {
|
| 474 |
-
font-size: 18px !important;
|
| 475 |
-
font-weight: bold !important;
|
| 476 |
-
color: #2E7D32 !important;
|
| 477 |
-
}
|
| 478 |
-
|
| 479 |
-
/* Make the download area more prominent */
|
| 480 |
-
.download-section {
|
| 481 |
-
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
|
| 482 |
-
border-radius: 15px !important;
|
| 483 |
-
padding: 25px !important;
|
| 484 |
-
margin: 20px 0 !important;
|
| 485 |
-
color: white !important;
|
| 486 |
-
}
|
| 487 |
-
|
| 488 |
-
.download-section .block {
|
| 489 |
-
background: rgba(255,255,255,0.1) !important;
|
| 490 |
-
border-radius: 10px !important;
|
| 491 |
-
padding: 15px !important;
|
| 492 |
-
}
|
| 493 |
-
"""
|
| 494 |
-
|
| 495 |
-
# Update your event handlers to use the new function
|
| 496 |
-
generate_btn.click(
|
| 497 |
-
fn=generate_with_progress,
|
| 498 |
-
inputs=all_inputs,
|
| 499 |
-
outputs=[json_output, download_status, download_btn, download_html, download_file],
|
| 500 |
-
show_progress="full"
|
| 501 |
-
)
|
| 502 |
-
|
| 503 |
-
# Optional: Add click handler for the download button to provide feedback
|
| 504 |
-
def handle_download_click():
|
| 505 |
-
return gr.Markdown("🎉 *Download initiated! Check your downloads folder.*")
|
| 506 |
-
|
| 507 |
-
download_btn.click(
|
| 508 |
-
fn=handle_download_click,
|
| 509 |
-
outputs=[download_status]
|
| 510 |
-
)
|
| 511 |
|
| 512 |
def clear_form():
|
| 513 |
"""Clear all form inputs"""
|
|
|
|
| 353 |
label="Scorecard JSON",
|
| 354 |
show_label=True
|
| 355 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 356 |
|
| 357 |
+
with gr.Row():
|
| 358 |
download_file = gr.File(
|
| 359 |
+
label="⬇️ Download Scorecard",
|
| 360 |
+
#visible=False,
|
| 361 |
+
variant="primary",
|
| 362 |
+
size="lg",
|
| 363 |
+
scale=2
|
| 364 |
)
|
| 365 |
+
|
| 366 |
# Event handlers
|
| 367 |
all_inputs = system_inputs + eval_inputs
|
| 368 |
|
|
|
|
| 380 |
with open(filename, 'w') as f:
|
| 381 |
f.write(json_content)
|
| 382 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 383 |
return (
|
| 384 |
scorecard, # JSON display
|
| 385 |
+
gr.File(value=filename, visible=True), # File for download
|
|
|
|
| 386 |
)
|
| 387 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 388 |
|
| 389 |
def clear_form():
|
| 390 |
"""Clear all form inputs"""
|