Wajahat698 commited on
Commit
4d9cf4f
·
verified ·
1 Parent(s): 9dc1a68

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -6
app.py CHANGED
@@ -301,6 +301,9 @@ def analyze_prospects_data(file_path):
301
  """
302
  Analyze prospects data focusing on Purchase Consideration as target.
303
  """
 
 
 
304
  logger.info("Analyzing prospects file: %s", file_path)
305
 
306
  try:
@@ -382,7 +385,20 @@ def analyze_prospects_data(file_path):
382
 
383
  except Exception as e:
384
  logger.error(f"Error analyzing data: {e}")
385
- raise
 
 
 
 
 
 
 
 
 
 
 
 
 
386
 
387
  # Gradio interface with light theme
388
  css = """
@@ -415,6 +431,15 @@ with gr.Blocks(css=css, js=js, theme=gr.themes.Soft()) as demo:
415
  gr.Markdown("### Prospects Analysis")
416
  gr.Markdown("Analysis showing what drives Purchase Consideration among prospects")
417
 
 
 
 
 
 
 
 
 
 
418
  # Metrics row
419
  with gr.Row(equal_height=True):
420
  with gr.Column(scale=1):
@@ -429,13 +454,23 @@ with gr.Blocks(css=css, js=js, theme=gr.themes.Soft()) as demo:
429
  with gr.Column():
430
  driver_analysis_plot = gr.Image(show_label=False)
431
 
432
- # Hidden state for file path
433
- prospects_file = gr.State(value="example_files/Volkswagen Non Customers.xlsx")
 
 
 
 
 
 
 
 
 
 
434
 
435
- # Auto-load on page load
436
  demo.load(
437
- fn=analyze_prospects_data,
438
- inputs=[prospects_file],
439
  outputs=[r2_output, avg_target_output, factor_performance_plot, driver_analysis_plot]
440
  )
441
 
 
301
  """
302
  Analyze prospects data focusing on Purchase Consideration as target.
303
  """
304
+ if file_path is None:
305
+ return None, None, None, None
306
+
307
  logger.info("Analyzing prospects file: %s", file_path)
308
 
309
  try:
 
385
 
386
  except Exception as e:
387
  logger.error(f"Error analyzing data: {e}")
388
+ return None, None, None, None
389
+
390
+ def load_default_file():
391
+ """Load default file on startup"""
392
+ default_file = "example_files/Volkswagen Non Customers.xlsx"
393
+ if os.path.exists(default_file):
394
+ return analyze_prospects_data(default_file)
395
+ return None, None, None, None
396
+
397
+ def handle_file_upload(file):
398
+ """Handle file upload and analysis"""
399
+ if file is None:
400
+ return None, None, None, None
401
+ return analyze_prospects_data(file.name)
402
 
403
  # Gradio interface with light theme
404
  css = """
 
431
  gr.Markdown("### Prospects Analysis")
432
  gr.Markdown("Analysis showing what drives Purchase Consideration among prospects")
433
 
434
+ # File upload section
435
+ with gr.Row():
436
+ file_upload = gr.File(
437
+ label="Upload Excel File (optional - default file will be used if none uploaded)",
438
+ file_types=[".xlsx", ".xls"],
439
+ type="filepath"
440
+ )
441
+ analyze_btn = gr.Button("Analyze", variant="primary")
442
+
443
  # Metrics row
444
  with gr.Row(equal_height=True):
445
  with gr.Column(scale=1):
 
454
  with gr.Column():
455
  driver_analysis_plot = gr.Image(show_label=False)
456
 
457
+ # Event handlers
458
+ analyze_btn.click(
459
+ fn=handle_file_upload,
460
+ inputs=[file_upload],
461
+ outputs=[r2_output, avg_target_output, factor_performance_plot, driver_analysis_plot]
462
+ )
463
+
464
+ file_upload.change(
465
+ fn=handle_file_upload,
466
+ inputs=[file_upload],
467
+ outputs=[r2_output, avg_target_output, factor_performance_plot, driver_analysis_plot]
468
+ )
469
 
470
+ # Auto-load default file on page load
471
  demo.load(
472
+ fn=load_default_file,
473
+ inputs=[],
474
  outputs=[r2_output, avg_target_output, factor_performance_plot, driver_analysis_plot]
475
  )
476