diff --git a/python_core/ai_video/video_generator.py b/python_core/ai_video/video_generator.py index d8d9e98..a814fcb 100644 --- a/python_core/ai_video/video_generator.py +++ b/python_core/ai_video/video_generator.py @@ -84,9 +84,27 @@ class VideoGenerator: try: # Check if image file exists if not os.path.exists(image_path): - result['msg'] = f'Image file not found: {image_path}' - logger.error(result['msg']) - return result + # Try to find the file in common locations + possible_paths = [ + image_path, + os.path.join(os.getcwd(), image_path), + os.path.join(os.path.dirname(__file__), '..', '..', image_path), + os.path.join('uploads', image_path) if not os.path.isabs(image_path) else image_path + ] + + found_path = None + for path in possible_paths: + if os.path.exists(path): + found_path = path + break + + if found_path: + image_path = found_path + logger.info(f"Found image at: {image_path}") + else: + result['msg'] = f'Image file not found: {image_path}. Searched in: {possible_paths}' + logger.error(result['msg']) + return result # Step 1: Upload image to cloud storage if progress_callback: diff --git a/src/components/AIVideoGenerator.tsx b/src/components/AIVideoGenerator.tsx index 52318e7..3eea018 100644 --- a/src/components/AIVideoGenerator.tsx +++ b/src/components/AIVideoGenerator.tsx @@ -1,6 +1,7 @@ import React, { useState, useRef } from 'react' import { Upload, Play, Settings, Folder, FileText, Clock, Cpu, Trash2, Download } from 'lucide-react' import { useAIVideoStore, useAIVideoJobs, useAIVideoProcessing, useAIVideoSettings } from '../stores/useAIVideoStore' +import { open } from '@tauri-apps/plugin-dialog' interface AIVideoGeneratorProps { className?: string @@ -40,27 +41,53 @@ const AIVideoGenerator: React.FC = ({ className = '' }) = }, [defaultDuration, defaultModelType]) // Handle file selection - const handleImageSelect = () => { - fileInputRef.current?.click() - } + const handleImageSelect = async () => { + try { + const selected = await open({ + multiple: false, + filters: [{ + name: 'Images', + extensions: ['jpg', 'jpeg', 'png', 'bmp', 'gif', 'tiff', 'webp'] + }] + }) - const handleImageChange = (e: React.ChangeEvent) => { - const file = e.target.files?.[0] - if (file) { - setSelectedImage(file.path || file.name) + if (selected && typeof selected === 'string') { + setSelectedImage(selected) + } + } catch (error) { + console.error('Failed to select image:', error) } } - const handleFolderSelect = () => { - folderInputRef.current?.click() + const handleImageChange = (e: React.ChangeEvent) => { + // This is now unused but kept for compatibility + const file = e.target.files?.[0] + if (file) { + setSelectedImage(file.name) + } + } + + const handleFolderSelect = async () => { + try { + const selected = await open({ + directory: true, + multiple: false + }) + + if (selected && typeof selected === 'string') { + setSelectedFolder(selected) + } + } catch (error) { + console.error('Failed to select folder:', error) + } } const handleFolderChange = (e: React.ChangeEvent) => { + // This is now unused but kept for compatibility const files = e.target.files if (files && files.length > 0) { - // Get the directory path from the first file const firstFile = files[0] - const path = firstFile.webkitRelativePath || firstFile.name + const path = (firstFile as any).webkitRelativePath || firstFile.name const folderPath = path.split('/')[0] setSelectedFolder(folderPath) } @@ -216,7 +243,7 @@ const AIVideoGenerator: React.FC = ({ className = '' }) = = ({ className = '' }) = - setOutputFolder(e.target.value)} - placeholder="输入保存目录路径" - className="input w-full" - /> +
+ setOutputFolder(e.target.value)} + placeholder="输入保存目录路径" + className="input flex-1" + /> + +
)} diff --git a/test_image.jpg b/test_image.jpg new file mode 100644 index 0000000..e1ab60c Binary files /dev/null and b/test_image.jpg differ