Yash Claude Sonnet 4.6 commited on
Commit
86bf96d
·
1 Parent(s): 18106f7

Fix Gradio filepath handling — use str path directly instead of .name attribute

Browse files

With type="filepath", Gradio passes plain string paths rather than file
objects, so accessing .name caused AttributeError. Now handles both cases
gracefully for both the IP check and narration matching pipelines.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -90,9 +90,11 @@ def run_ip_check(pdf_file, skip_quality, progress=gr.Progress(track_tqdm=True)):
90
  os.makedirs(work_dir, exist_ok=True)
91
 
92
  # Copy uploaded PDF to working dir
 
 
93
  pdf_path = os.path.join(work_dir, "input.pdf")
94
- shutil.copy(pdf_file.name, pdf_path)
95
- pdf_name = os.path.splitext(os.path.basename(pdf_file.name))[0]
96
 
97
  try:
98
  # Override settings for this run
@@ -154,7 +156,7 @@ def run_ip_check(pdf_file, skip_quality, progress=gr.Progress(track_tqdm=True)):
154
  uploader=uploader,
155
  thumbnail_map=thumbnail_map,
156
  sheet_id=sheet_id,
157
- source_file=os.path.basename(pdf_file.name),
158
  results_sheet_url=sheet_url,
159
  )
160
  )
@@ -238,14 +240,16 @@ def run_narration_match(
238
  os.makedirs(work_dir, exist_ok=True)
239
  os.makedirs(audio_dir, exist_ok=True)
240
 
241
- # Copy PDF
 
242
  pdf_path = os.path.join(work_dir, "input.pdf")
243
- shutil.copy(pdf_file.name, pdf_path)
244
- pdf_name = os.path.splitext(os.path.basename(pdf_file.name))[0]
245
 
246
- # Copy audio files — sorted by name (ch01.mp3, ch02.mp3, ...)
247
  audio_paths = sorted(
248
- [f.name for f in audio_files], key=lambda p: os.path.basename(p).lower()
 
249
  )
250
  for src in audio_paths:
251
  dst = os.path.join(audio_dir, os.path.basename(src))
 
90
  os.makedirs(work_dir, exist_ok=True)
91
 
92
  # Copy uploaded PDF to working dir
93
+ # With type="filepath", Gradio passes the path as a plain string
94
+ pdf_src = pdf_file if isinstance(pdf_file, str) else pdf_file.name
95
  pdf_path = os.path.join(work_dir, "input.pdf")
96
+ shutil.copy(pdf_src, pdf_path)
97
+ pdf_name = os.path.splitext(os.path.basename(pdf_src))[0]
98
 
99
  try:
100
  # Override settings for this run
 
156
  uploader=uploader,
157
  thumbnail_map=thumbnail_map,
158
  sheet_id=sheet_id,
159
+ source_file=os.path.basename(pdf_src),
160
  results_sheet_url=sheet_url,
161
  )
162
  )
 
240
  os.makedirs(work_dir, exist_ok=True)
241
  os.makedirs(audio_dir, exist_ok=True)
242
 
243
+ # Copy PDF — with type="filepath", Gradio gives a plain string path
244
+ pdf_src = pdf_file if isinstance(pdf_file, str) else pdf_file.name
245
  pdf_path = os.path.join(work_dir, "input.pdf")
246
+ shutil.copy(pdf_src, pdf_path)
247
+ pdf_name = os.path.splitext(os.path.basename(pdf_src))[0]
248
 
249
+ # Copy audio files — audio_files is a list of strings (filepath mode)
250
  audio_paths = sorted(
251
+ [f if isinstance(f, str) else f.name for f in audio_files],
252
+ key=lambda p: os.path.basename(p).lower(),
253
  )
254
  for src in audio_paths:
255
  dst = os.path.join(audio_dir, os.path.basename(src))