Fancellu commited on
Commit
a5980f8
ยท
1 Parent(s): 7ae1bfc

Trying change in download buttons, which wouldn't work in HF Spcaes

Browse files
Files changed (1) hide show
  1. app.py +18 -21
app.py CHANGED
@@ -241,13 +241,13 @@ class MBTIPocketFlowApp:
241
  {str(type_badge) if type_badge else f'<div style="background: #4CAF50; color: white; padding: 10px 20px; border-radius: 5px; display: inline-block;">{mbti_type}</div>'}
242
  {f'<p><em>{type_desc.text}</em></p>' if type_desc else ''}
243
  </div>
244
-
245
  {responses_table_html}
246
-
247
  {strengths_html}
248
  {weaknesses_html}
249
  {careers_html}
250
-
251
  <div style="margin: 20px 0;">
252
  <h2 style="color: #333; border-bottom: 2px solid #4CAF50;">Traditional Dimension Scores</h2>
253
  <ul>
@@ -369,8 +369,8 @@ def create_pocketflow_gradio_app():
369
  export_btn = gr.Button("๐Ÿ’พ Export Current Progress", variant="secondary")
370
  reset_btn = gr.Button("Reset Questionnaire")
371
 
372
- # Hidden download button
373
- export_download_btn = gr.DownloadButton(visible=False, elem_id="export_download_btn")
374
 
375
  # Analysis section
376
  with gr.Column(visible=False) as analyze_section:
@@ -385,8 +385,8 @@ def create_pocketflow_gradio_app():
385
  # Download report button
386
  download_report_btn = gr.Button("๐Ÿ“Š Download Report", visible=False)
387
 
388
- # Hidden download button for report
389
- download_report_hidden = gr.DownloadButton(visible=False, elem_id="download_report_hidden")
390
 
391
  # Event handlers
392
  length_radio.change(
@@ -418,17 +418,14 @@ def create_pocketflow_gradio_app():
418
  # Save current response and create file
419
  file_path = app.save_current_questionnaire(idx, resp)
420
  print(f"DEBUG: Export file path: {file_path}")
421
- return file_path if file_path else None
 
 
422
 
423
  export_btn.click(
424
  export_handler,
425
  inputs=[question_idx, response_slider],
426
- outputs=[export_download_btn]
427
- ).then(
428
- fn=None,
429
- inputs=None,
430
- outputs=None,
431
- js="() => document.querySelector('#export_download_btn').click()"
432
  )
433
 
434
  analyze_btn.click(
@@ -446,14 +443,14 @@ def create_pocketflow_gradio_app():
446
  )
447
 
448
  # Download report
 
 
 
 
 
449
  download_report_btn.click(
450
- lambda: app.last_report_path if app.last_report_path else None,
451
- outputs=[download_report_hidden]
452
- ).then(
453
- fn=None,
454
- inputs=None,
455
- outputs=None,
456
- js="() => document.querySelector('#download_report_hidden').click()"
457
  )
458
 
459
  # Auto-save when slider changes and check for analysis button
 
241
  {str(type_badge) if type_badge else f'<div style="background: #4CAF50; color: white; padding: 10px 20px; border-radius: 5px; display: inline-block;">{mbti_type}</div>'}
242
  {f'<p><em>{type_desc.text}</em></p>' if type_desc else ''}
243
  </div>
244
+
245
  {responses_table_html}
246
+
247
  {strengths_html}
248
  {weaknesses_html}
249
  {careers_html}
250
+
251
  <div style="margin: 20px 0;">
252
  <h2 style="color: #333; border-bottom: 2px solid #4CAF50;">Traditional Dimension Scores</h2>
253
  <ul>
 
369
  export_btn = gr.Button("๐Ÿ’พ Export Current Progress", variant="secondary")
370
  reset_btn = gr.Button("Reset Questionnaire")
371
 
372
+ # File output for export
373
+ export_file_output = gr.File(label="Download Questionnaire", visible=False)
374
 
375
  # Analysis section
376
  with gr.Column(visible=False) as analyze_section:
 
385
  # Download report button
386
  download_report_btn = gr.Button("๐Ÿ“Š Download Report", visible=False)
387
 
388
+ # File output for report download
389
+ report_file_output = gr.File(label="Download Report", visible=False)
390
 
391
  # Event handlers
392
  length_radio.change(
 
418
  # Save current response and create file
419
  file_path = app.save_current_questionnaire(idx, resp)
420
  print(f"DEBUG: Export file path: {file_path}")
421
+ if file_path:
422
+ return gr.update(value=file_path, visible=True)
423
+ return gr.update()
424
 
425
  export_btn.click(
426
  export_handler,
427
  inputs=[question_idx, response_slider],
428
+ outputs=[export_file_output]
 
 
 
 
 
429
  )
430
 
431
  analyze_btn.click(
 
443
  )
444
 
445
  # Download report
446
+ def report_download_handler():
447
+ if app.last_report_path:
448
+ return gr.update(value=app.last_report_path, visible=True)
449
+ return gr.update()
450
+
451
  download_report_btn.click(
452
+ report_download_handler,
453
+ outputs=[report_file_output]
 
 
 
 
 
454
  )
455
 
456
  # Auto-save when slider changes and check for analysis button