euler314 commited on
Commit
455ef67
·
verified ·
1 Parent(s): f81cb89

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -33
app.py CHANGED
@@ -423,46 +423,46 @@ class DownloadManager:
423
  base, ext = os.path.splitext(fname)
424
  counter = 1
425
  while os.path.exists(path):
426
- path = os.path.join(save_dir, f"{base}_{counter}{ext}")
427
- counter += 1
428
 
429
  os.makedirs(save_dir, exist_ok=True)
430
 
431
  try:
432
- if "drive.google.com" in file_url:
433
- import gdown
434
- try:
435
- st.write(f"Downloading from Google Drive: {fname}")
436
-
437
- # Determine file extension or use a default if none available
438
- if not ext or ext == "":
439
  # Try to determine file type from content-type header
440
- async with self.context.new_page() as page:
441
- response = await page.request.head(file_url, timeout=15000)
442
- content_type = response.headers.get('Content-Type', '')
443
-
444
- # Map content types to extensions
445
- extension_map = {
446
- 'application/pdf': '.pdf',
447
- 'image/jpeg': '.jpg',
448
- 'image/png': '.png',
449
- 'application/msword': '.doc',
450
- 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': '.docx',
451
- 'application/zip': '.zip',
452
- 'text/plain': '.txt',
453
- 'application/vnd.ms-excel': '.xls',
454
- 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': '.xlsx'
455
- }
456
 
457
- # Get extension from content type or use .bin as fallback
458
- ext = extension_map.get(content_type.split(';')[0], '.bin')
459
- path = os.path.join(save_dir, f"{base}{ext}")
460
 
461
- # Handle name collisions
462
- counter = 1
463
- while os.path.exists(path):
464
- path = os.path.join(save_dir, f"{base}_{counter}{ext}")
465
- counter += 1
466
 
467
  output = gdown.download(file_url, path, quiet=False)
468
  if output:
 
423
  base, ext = os.path.splitext(fname)
424
  counter = 1
425
  while os.path.exists(path):
426
+ path = os.path.join(save_dir, f"{base}_{counter}{ext}")
427
+ counter += 1
428
 
429
  os.makedirs(save_dir, exist_ok=True)
430
 
431
  try:
432
+ if "drive.google.com" in file_url:
433
+ import gdown
434
+ try:
435
+ st.write(f"Downloading from Google Drive: {fname}")
436
+
437
+ # Determine file extension or use a default if none available
438
+ if not ext or ext == "":
439
  # Try to determine file type from content-type header
440
+ async with self.context.new_page() as page:
441
+ response = await page.request.head(file_url, timeout=15000)
442
+ content_type = response.headers.get('Content-Type', '')
443
+
444
+ # Map content types to extensions
445
+ extension_map = {
446
+ 'application/pdf': '.pdf',
447
+ 'image/jpeg': '.jpg',
448
+ 'image/png': '.png',
449
+ 'application/msword': '.doc',
450
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': '.docx',
451
+ 'application/zip': '.zip',
452
+ 'text/plain': '.txt',
453
+ 'application/vnd.ms-excel': '.xls',
454
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': '.xlsx'
455
+ }
456
 
457
+ # Get extension from content type or use .bin as fallback
458
+ ext = extension_map.get(content_type.split(';')[0], '.bin')
459
+ path = os.path.join(save_dir, f"{base}{ext}")
460
 
461
+ # Handle name collisions
462
+ counter = 1
463
+ while os.path.exists(path):
464
+ path = os.path.join(save_dir, f"{base}_{counter}{ext}")
465
+ counter += 1
466
 
467
  output = gdown.download(file_url, path, quiet=False)
468
  if output: