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