From 060730165a25e6a63dc0dfeb8fe8e64c6eaca792 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 11 Jul 2025 13:54:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=91=BD=E4=BB=A4=E8=A1=8C=E7=AA=97?= =?UTF-8?q?=E5=8F=A3=E9=97=AA=E7=8E=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README_AI_CONTENT_GENERATOR.md | 183 +++++++++++++++++++++++++++++ src-tauri/src/commands/ai_video.rs | 26 +++- src-tauri/src/commands/project.rs | 21 +++- src-tauri/src/python_executor.rs | 54 +++++++-- 4 files changed, 265 insertions(+), 19 deletions(-) create mode 100644 README_AI_CONTENT_GENERATOR.md diff --git a/README_AI_CONTENT_GENERATOR.md b/README_AI_CONTENT_GENERATOR.md new file mode 100644 index 0000000..e4551db --- /dev/null +++ b/README_AI_CONTENT_GENERATOR.md @@ -0,0 +1,183 @@ +# AI 内容生成器 - 使用指南 + +## 概述 + +我们已经成功在 MixVideo V2 首页添加了 AI 内容生成器的入口,基于 Text Video Agent API 提供强大的智能内容生成功能。 + +## 🚀 功能入口 + +### 1. 首页主要入口 +- **位置**: 首页欢迎区域的主要按钮 +- **按钮**: "AI 内容生成" (蓝色主按钮) +- **图标**: 魔法棒图标 (Wand2) + +### 2. 快速操作入口 +- **位置**: 首页快速操作卡片区域 +- **卡片**: "AI 内容生成" +- **描述**: "基于 Text Video Agent API 的智能内容生成" + +### 3. 侧边栏导航入口 +- **位置**: 左侧导航栏 +- **菜单项**: "AI 内容生成" +- **路径**: `/text-video-generator` + +## 📱 页面功能 + +### 主要功能区域 + +#### 1. **内容生成器** (左侧主要区域) +- **提示词输入**: 支持多行文本输入 +- **参数配置**: + - 任务类型: Vlog, 茶文化, 人物, 烹饪 + - 长宽比: 9:16, 16:9, 1:1 + - 视频时长: 3秒, 5秒, 10秒 +- **参考图片上传**: 可选的参考图片 +- **生成选项**: 可选择同时生成视频 + +#### 2. **信息面板** (右侧) +- **功能介绍**: 详细的功能说明 +- **任务类型说明**: 各种任务类型的用途 +- **生成统计**: 本次会话的生成统计 +- **最近生成**: 显示最新生成的内容 +- **使用提示**: 实用的使用建议 + +### 操作按钮 + +#### 主要操作 +- **生成内容**: 端到端的完整生成流程 +- **仅生成图片**: 只生成图片内容 +- **基于图片生成视频**: 使用已生成的图片创建视频 +- **取消**: 取消当前正在进行的操作 +- **重置**: 清除所有输入和结果 + +#### 状态显示 +- **实时进度**: 显示当前处理步骤和进度百分比 +- **错误提示**: 友好的错误信息显示 +- **连接状态**: API 连接状态指示 + +## 🔧 技术特性 + +### API 集成 +- **Text Video Agent API**: 完整的 API 封装 +- **图片生成**: 基于 Midjourney 的高质量图片生成 +- **视频生成**: 基于极梦的视频生成功能 +- **文件上传**: 支持参考图片上传 +- **图片分析**: AI 图片内容描述 + +### React Hook +- **useTextVideoAgent**: 状态管理和 API 调用 +- **useTaskPolling**: 任务状态轮询 +- **错误处理**: 完善的错误处理机制 +- **进度跟踪**: 实时进度更新 + +### 用户体验 +- **响应式设计**: 适配不同屏幕尺寸 +- **实时反馈**: 即时的状态更新和进度显示 +- **直观界面**: 清晰的视觉层次和交互反馈 +- **错误友好**: 完善的错误处理和恢复机制 + +## 📋 使用流程 + +### 基础使用 +1. **进入页面**: 通过首页任意入口进入 AI 内容生成器 +2. **输入提示词**: 在文本框中描述想要生成的内容 +3. **配置参数**: 选择任务类型、长宽比、视频时长等 +4. **开始生成**: 点击"生成内容"按钮 +5. **查看结果**: 在结果区域查看生成的图片和视频 + +### 高级使用 +1. **上传参考图片**: 提供参考图片以提高生成质量 +2. **分步生成**: 先生成图片,再基于图片生成视频 +3. **批量生成**: 使用不同参数生成多个版本 +4. **结果管理**: 下载和保存生成的内容 + +## 🎯 使用示例 + +### 示例1: 生成产品展示视频 +``` +提示词: "一个现代简约的咖啡杯,温暖的灯光,木质桌面,专业产品摄影" +任务类型: Vlog +长宽比: 9:16 +视频时长: 5秒 +``` + +### 示例2: 生成人物肖像 +``` +提示词: "一位优雅的女性,微笑着品茶,自然光线,温馨的下午时光" +任务类型: 人物 +长宽比: 9:16 +参考图片: 上传人物参考照片 +``` + +### 示例3: 生成烹饪场景 +``` +提示词: "专业厨师在制作精美料理,动作流畅,厨房环境,美食摄影" +任务类型: 烹饪 +长宽比: 16:9 +视频时长: 10秒 +``` + +## 🔍 功能亮点 + +### 1. **智能化生成** +- 基于先进的 AI 模型 +- 支持多种内容类型 +- 高质量的输出结果 + +### 2. **用户友好** +- 直观的操作界面 +- 实时的进度反馈 +- 详细的使用指导 + +### 3. **灵活配置** +- 多种参数选项 +- 自定义生成设置 +- 支持参考图片 + +### 4. **完整流程** +- 端到端的生成流程 +- 从图片到视频的完整链路 +- 结果预览和下载 + +## 🚨 注意事项 + +### 使用限制 +- 生成过程可能需要 1-3 分钟 +- 需要稳定的网络连接 +- API 可能有使用配额限制 + +### 最佳实践 +- 提示词要具体详细 +- 合理选择参数配置 +- 可以多次尝试不同设置 +- 及时保存满意的结果 + +### 故障排除 +- 如果生成失败,可以尝试重新生成 +- 检查网络连接状态 +- 简化提示词内容 +- 联系技术支持 + +## 🔗 相关链接 + +- **API 文档**: https://bowongai-dev--text-video-agent-fastapi-app.modal.run/docs +- **项目仓库**: 本地项目目录 +- **技术支持**: 开发团队 + +## 📈 未来规划 + +### 短期计划 +- [ ] 添加更多任务类型 +- [ ] 优化生成速度 +- [ ] 增加批量处理功能 +- [ ] 支持更多文件格式 + +### 长期规划 +- [ ] 集成更多 AI 模型 +- [ ] 添加风格迁移功能 +- [ ] 支持实时预览 +- [ ] 云端存储集成 + +--- + +通过这个 AI 内容生成器,用户可以轻松创建高质量的图片和视频内容,大大提升创作效率和内容质量。 diff --git a/src-tauri/src/commands/ai_video.rs b/src-tauri/src/commands/ai_video.rs index cd7776e..1ed3e56 100644 --- a/src-tauri/src/commands/ai_video.rs +++ b/src-tauri/src/commands/ai_video.rs @@ -2,6 +2,14 @@ use serde::Deserialize; use std::process::Command; use crate::python_executor::execute_python_command; +// Windows-specific imports for hiding console window +#[cfg(target_os = "windows")] +use std::os::windows::process::CommandExt; + +// Windows process creation flags +#[cfg(target_os = "windows")] +const CREATE_NO_WINDOW: u32 = 0x08000000; + #[derive(Debug, Deserialize)] pub struct AIVideoRequest { pub image_path: String, @@ -109,10 +117,20 @@ pub async fn test_ai_video_environment(_app: tauri::AppHandle) -> Result { diff --git a/src-tauri/src/commands/project.rs b/src-tauri/src/commands/project.rs index a663327..90b7f05 100644 --- a/src-tauri/src/commands/project.rs +++ b/src-tauri/src/commands/project.rs @@ -2,6 +2,14 @@ use serde::{Deserialize, Serialize}; use tauri::{command, AppHandle}; use crate::python_executor::execute_python_command; +// Windows-specific imports for hiding console window +#[cfg(target_os = "windows")] +use std::os::windows::process::CommandExt; + +// Windows process creation flags +#[cfg(target_os = "windows")] +const CREATE_NO_WINDOW: u32 = 0x08000000; + #[derive(Debug, Serialize, Deserialize)] pub struct ProjectInfo { pub name: String, @@ -71,9 +79,16 @@ pub async fn scan_directory(app: AppHandle, directory_path: String) -> Result Result<(), String> { #[cfg(target_os = "windows")] { - std::process::Command::new("cmd") - .args(["/C", "start", "", &file_path]) - .spawn() + let mut cmd = std::process::Command::new("cmd"); + cmd.args(["/C", "start", "", &file_path]); + + // Hide console window in release builds + #[cfg(not(debug_assertions))] + { + cmd.creation_flags(CREATE_NO_WINDOW); + } + + cmd.spawn() .map_err(|e| format!("Failed to open file: {}", e))?; } diff --git a/src-tauri/src/python_executor.rs b/src-tauri/src/python_executor.rs index ddbba56..4c90ea9 100644 --- a/src-tauri/src/python_executor.rs +++ b/src-tauri/src/python_executor.rs @@ -7,6 +7,46 @@ use std::sync::mpsc; use serde::{Deserialize, Serialize}; use tauri::{AppHandle, Emitter}; +// Windows-specific imports for hiding console window +#[cfg(target_os = "windows")] +use std::os::windows::process::CommandExt; + +// Windows process creation flags +#[cfg(target_os = "windows")] +const CREATE_NO_WINDOW: u32 = 0x08000000; + +/// Configure a Command for Python execution with proper console window handling +fn configure_python_command(cmd: &mut Command, project_root: &std::path::Path, args: &[String]) { + cmd.current_dir(project_root); + cmd.args(args); + cmd.stdout(std::process::Stdio::piped()); + cmd.stderr(std::process::Stdio::piped()); + + // Set environment variables for consistent encoding + cmd.env("PYTHONIOENCODING", "utf-8"); + cmd.env("PYTHONUNBUFFERED", "1"); + + // Platform-specific configurations + if cfg!(target_os = "windows") { + cmd.env("PYTHONUTF8", "1"); + + // Hide console window in release builds to prevent flashing + // In debug builds, keep console visible for debugging + #[cfg(target_os = "windows")] + { + #[cfg(not(debug_assertions))] + { + cmd.creation_flags(CREATE_NO_WINDOW); + println!("Console window hidden for release build"); + } + #[cfg(debug_assertions)] + { + println!("Console window visible for debug build"); + } + } + } +} + /// Generic progress information from Python processes #[derive(Debug, Serialize, Deserialize, Clone)] pub struct PythonProgress { @@ -281,19 +321,9 @@ where for python_cmd in python_commands { println!("Trying Python command: {}", python_cmd); let mut cmd = Command::new(python_cmd); - cmd.current_dir(&project_root); - cmd.args(args); - cmd.stdout(std::process::Stdio::piped()); - cmd.stderr(std::process::Stdio::piped()); - // Set environment variables for consistent encoding - cmd.env("PYTHONIOENCODING", "utf-8"); - cmd.env("PYTHONUNBUFFERED", "1"); - - // On Windows, ensure UTF-8 console output - if cfg!(target_os = "windows") { - cmd.env("PYTHONUTF8", "1"); - } + // Configure the command with proper console window handling + configure_python_command(&mut cmd, &project_root, args); match cmd.spawn() { Ok(process) => {