Developer commited on
Commit
a3b8422
·
1 Parent(s): 335b2c9

Add missing download_file method to OmniAvatarAPI

Browse files

CRITICAL FIX: Added missing download_file method that was causing AttributeError
- async def download_file(url, suffix) -> str
- Downloads files from URLs to temporary locations using aiohttp
- Handles HTTP errors and file creation
- Returns temporary file path for processing
- Used by generate_avatar for downloading audio and image files
- Includes proper error handling and logging

This fixes: 'OmniAvatarAPI' object has no attribute 'download_file'

Files changed (1) hide show
  1. app_main.py +26 -0
app_main.py CHANGED
@@ -318,6 +318,32 @@ class OmniAvatarAPI:
318
  logger.info(f"? SUCCESS: Downloaded models loaded - Video: {video_files}, Audio: {audio_files}")
319
  return True
320
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
321
  # Fallback: Check traditional OmniAvatar paths
322
  traditional_paths = [
323
  "./pretrained_models/Wan2.1-T2V-14B",
 
318
  logger.info(f"? SUCCESS: Downloaded models loaded - Video: {video_files}, Audio: {audio_files}")
319
  return True
320
 
321
+ async def download_file(self, url: str, suffix: str = '') -> str:
322
+ """Download file from URL to temporary location"""
323
+ import aiohttp
324
+ import tempfile
325
+ import os
326
+
327
+ try:
328
+ async with aiohttp.ClientSession() as session:
329
+ async with session.get(url) as response:
330
+ if response.status != 200:
331
+ raise Exception(f"Failed to download {url}: HTTP {response.status}")
332
+
333
+ # Create temporary file with appropriate suffix
334
+ with tempfile.NamedTemporaryFile(suffix=suffix, delete=False) as tmp_file:
335
+ content = await response.read()
336
+ tmp_file.write(content)
337
+ temp_path = tmp_file.name
338
+
339
+ logger.info(f"Downloaded {len(content)} bytes from {url} to {temp_path}")
340
+ return temp_path
341
+
342
+ except Exception as e:
343
+ logger.error(f"Failed to download file from {url}: {e}")
344
+ raise HTTPException(status_code=400, detail=f"Failed to download file: {e}")
345
+
346
+
347
  # Fallback: Check traditional OmniAvatar paths
348
  traditional_paths = [
349
  "./pretrained_models/Wan2.1-T2V-14B",