Tobaly commited on
Commit
6966521
·
verified ·
1 Parent(s): 11bc7c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -19
app.py CHANGED
@@ -512,28 +512,33 @@ class ComprehensivePodcastReport:
512
  def process_uploaded_files(files):
513
  """Process uploaded files and return file content dictionary."""
514
  file_contents = {}
 
 
 
 
 
 
 
515
  for file in files:
516
- if file is not None:
517
  # Read file content
518
- content = file.read()
519
- if isinstance(content, bytes):
520
- content = content.decode('utf-8')
521
- file_contents[file.name] = content
522
  return file_contents
523
 
524
 
525
- def run_podcast_analysis(client_name, date_from, date_to, gemini_api_key, *uploaded_files):
526
  """Main function to run the podcast analysis with Gradio inputs."""
527
  try:
528
  print(f"🎙️ Starting analysis for: {client_name}")
529
  print(f"📅 Date range: {date_from} to {date_to}")
530
 
531
  # Process uploaded files
532
- all_files = [f for f in uploaded_files if f is not None]
533
- if not all_files:
534
  return "❌ Error: No files uploaded. Please upload the required CSV files.", []
535
 
536
- file_contents = process_uploaded_files(all_files)
537
  print(f"📁 Processed {len(file_contents)} files")
538
 
539
  # Separate general files from episode-specific files
@@ -653,6 +658,13 @@ def create_gradio_interface():
653
  gr.HTML("<h3>📁 File Uploads</h3>")
654
  gr.HTML("""
655
  <div style="background-color: #f0f8ff; padding: 15px; border-radius: 8px; margin-bottom: 15px;">
 
 
 
 
 
 
 
656
  <h4>Required Files:</h4>
657
  <ul>
658
  <li><strong>OnSpotify</strong> CSV (daily plays data)</li>
@@ -669,15 +681,16 @@ def create_gradio_interface():
669
  </div>
670
  """)
671
 
672
- # Multiple file upload components
673
- files = []
674
- for i in range(20): # Allow up to 20 file uploads
675
- file_upload = gr.File(
676
- label=f"Upload CSV File {i+1}" if i < 6 else None,
677
- file_types=[".csv"],
678
- visible=i < 6 # Show first 6 by default
679
- )
680
- files.append(file_upload)
 
681
 
682
  analyze_btn = gr.Button("🚀 Generate Analytics Report", variant="primary", size="lg")
683
 
@@ -701,7 +714,7 @@ def create_gradio_interface():
701
  # Set up the analysis function
702
  analyze_btn.click(
703
  fn=run_podcast_analysis,
704
- inputs=[client_name, date_from, date_to, gemini_api_key] + files,
705
  outputs=[summary_output, plots_output],
706
  show_progress=True
707
  )
@@ -710,6 +723,7 @@ def create_gradio_interface():
710
  <div style="text-align: center; margin-top: 30px; padding: 20px; background-color: #f8f9fa; border-radius: 8px;">
711
  <h4>💡 Tips for Best Results:</h4>
712
  <ul style="text-align: left; display: inline-block;">
 
713
  <li>Ensure your CSV files follow Spotify for Creators naming conventions</li>
714
  <li>For Hebrew podcasts, provide a Gemini API key for title translation</li>
715
  <li>Include episode-specific CSV files for detailed performance tracking</li>
 
512
  def process_uploaded_files(files):
513
  """Process uploaded files and return file content dictionary."""
514
  file_contents = {}
515
+ if files is None:
516
+ return file_contents
517
+
518
+ # Handle both single file and list of files
519
+ if not isinstance(files, list):
520
+ files = [files]
521
+
522
  for file in files:
523
+ if file is not None and hasattr(file, 'name'):
524
  # Read file content
525
+ with open(file.name, 'r', encoding='utf-8') as f:
526
+ content = f.read()
527
+ file_contents[os.path.basename(file.name)] = content
 
528
  return file_contents
529
 
530
 
531
+ def run_podcast_analysis(client_name, date_from, date_to, gemini_api_key, uploaded_files):
532
  """Main function to run the podcast analysis with Gradio inputs."""
533
  try:
534
  print(f"🎙️ Starting analysis for: {client_name}")
535
  print(f"📅 Date range: {date_from} to {date_to}")
536
 
537
  # Process uploaded files
538
+ if not uploaded_files:
 
539
  return "❌ Error: No files uploaded. Please upload the required CSV files.", []
540
 
541
+ file_contents = process_uploaded_files(uploaded_files)
542
  print(f"📁 Processed {len(file_contents)} files")
543
 
544
  # Separate general files from episode-specific files
 
658
  gr.HTML("<h3>📁 File Uploads</h3>")
659
  gr.HTML("""
660
  <div style="background-color: #f0f8ff; padding: 15px; border-radius: 8px; margin-bottom: 15px;">
661
+ <h4>How to Upload:</h4>
662
+ <ul>
663
+ <li><strong>Drag & Drop:</strong> Simply drag all your CSV files onto the upload area</li>
664
+ <li><strong>Click to Browse:</strong> Click the upload area to select multiple files at once</li>
665
+ <li><strong>Bulk Upload:</strong> Upload 20+ files simultaneously - no individual file limits!</li>
666
+ <li><strong>Folder Upload:</strong> Select an entire folder containing your CSV files</li>
667
+ </ul>
668
  <h4>Required Files:</h4>
669
  <ul>
670
  <li><strong>OnSpotify</strong> CSV (daily plays data)</li>
 
681
  </div>
682
  """)
683
 
684
+ # Bulk file upload - much cleaner!
685
+ files_upload = gr.File(
686
+ label="📁 Upload All CSV Files (or drag & drop)",
687
+ file_types=[".csv"],
688
+ file_count="multiple",
689
+ height=120
690
+ )
691
+
692
+ # Alternative: Directory upload for advanced users
693
+ gr.HTML("<p style='text-align: center; margin: 10px 0; color: #666; font-size: 14px;'>💡 Tip: You can also select and upload an entire folder containing your CSV files</p>")
694
 
695
  analyze_btn = gr.Button("🚀 Generate Analytics Report", variant="primary", size="lg")
696
 
 
714
  # Set up the analysis function
715
  analyze_btn.click(
716
  fn=run_podcast_analysis,
717
+ inputs=[client_name, date_from, date_to, gemini_api_key, files_upload],
718
  outputs=[summary_output, plots_output],
719
  show_progress=True
720
  )
 
723
  <div style="text-align: center; margin-top: 30px; padding: 20px; background-color: #f8f9fa; border-radius: 8px;">
724
  <h4>💡 Tips for Best Results:</h4>
725
  <ul style="text-align: left; display: inline-block;">
726
+ <li>Drag and drop all your CSV files at once for fastest upload</li>
727
  <li>Ensure your CSV files follow Spotify for Creators naming conventions</li>
728
  <li>For Hebrew podcasts, provide a Gemini API key for title translation</li>
729
  <li>Include episode-specific CSV files for detailed performance tracking</li>