diff --git a/install_ai_video_deps.py b/install_ai_video_deps.py new file mode 100644 index 0000000..4664468 --- /dev/null +++ b/install_ai_video_deps.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python3 +""" +Install AI Video Dependencies +安装 AI 视频生成所需的依赖包 +""" + +import subprocess +import sys +import os + +def install_package(package_name, import_name=None): + """Install a Python package using pip""" + if import_name is None: + import_name = package_name + + try: + __import__(import_name) + print(f"✅ {package_name} is already installed") + return True + except ImportError: + print(f"📦 Installing {package_name}...") + try: + subprocess.check_call([sys.executable, "-m", "pip", "install", package_name]) + print(f"✅ {package_name} installed successfully") + return True + except subprocess.CalledProcessError as e: + print(f"❌ Failed to install {package_name}: {e}") + return False + +def main(): + """Main installation function""" + print("🚀 Installing AI Video Dependencies...") + print("=" * 50) + + # List of required packages + packages = [ + ("requests", "requests"), + ("cos-python-sdk-v5", "qcloud_cos"), + ("loguru", "loguru"), + ] + + success_count = 0 + total_count = len(packages) + + for package_name, import_name in packages: + if install_package(package_name, import_name): + success_count += 1 + + print("=" * 50) + print(f"📊 Installation Summary: {success_count}/{total_count} packages installed") + + if success_count == total_count: + print("🎉 All dependencies installed successfully!") + + # Test AI video module import + print("\n🧪 Testing AI video module import...") + try: + sys.path.append('python_core') + from ai_video import VideoGenerator + print("✅ AI video module imported successfully!") + except Exception as e: + print(f"❌ AI video module import failed: {e}") + return False + + return True + else: + print("❌ Some dependencies failed to install. Please check the errors above.") + return False + +if __name__ == "__main__": + success = main() + sys.exit(0 if success else 1) diff --git a/python_core/ai_video/api_client.py b/python_core/ai_video/api_client.py index 9a7f756..d733348 100644 --- a/python_core/ai_video/api_client.py +++ b/python_core/ai_video/api_client.py @@ -55,25 +55,32 @@ class APIClient: def submit_task(self, prompt: str, img_url: str, duration: str = '5', model_type: str = 'lite') -> Dict[str, Any]: """ Submit video generation task. - + Args: prompt: Text prompt for video generation - img_url: URL of the input image + img_url: URL of the input image (http/https URL or file:// for local files) duration: Video duration ('5' or '10') model_type: Model type ('lite' or 'pro') - + Returns: Dictionary with task submission result """ result = {'status': False, 'data': None, 'msg': ''} - + if duration not in ('5', '10'): result['msg'] = 'Duration must be either 5 or 10' return result - + if model_type not in self.models: result['msg'] = f'Model type must be one of: {list(self.models.keys())}' return result + + # Handle local file URLs + if img_url.startswith('file://'): + result['status'] = False + result['msg'] = 'Local files are not supported by the API. Please upload the image to cloud storage first.' + logger.error(f"Local file URL not supported: {img_url}") + return result try: import requests diff --git a/python_core/ai_video/cloud_storage.py b/python_core/ai_video/cloud_storage.py index 97c376b..8d39d34 100644 --- a/python_core/ai_video/cloud_storage.py +++ b/python_core/ai_video/cloud_storage.py @@ -57,6 +57,7 @@ class CloudStorage: """Initialize COS client.""" try: from qcloud_cos import CosConfig, CosS3Client + self.cos_available = True config = CosConfig( Region=self.region, @@ -69,6 +70,7 @@ class CloudStorage: except ImportError: logger.warning("qcloud_cos not installed. Cloud storage features will be disabled.") self.client = None + self.cos_available = False except Exception as e: logger.error(f"Failed to initialize COS client: {str(e)}") self.client = None @@ -86,6 +88,20 @@ class CloudStorage: """ result = {'status': False, 'data': '', 'msg': ''} + if not self.cos_available: + # Fallback to local file path when cloud storage is not available + if os.path.exists(file_path): + # Convert to file:// URL for consistency + file_url = f"file://{os.path.abspath(file_path)}" + result['status'] = True + result['data'] = file_url + result['msg'] = 'Using local file (cloud storage not available)' + logger.info(f"Using local file: {file_url}") + return result + else: + result['msg'] = f'Local file not found: {file_path}' + return result + if not self.client: result['msg'] = 'Cloud storage client not available' return result diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index cdfe8b7..71a389d 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -270,10 +270,16 @@ pub async fn generate_ai_video(request: AIVideoRequest) -> Result