Spaces:
Running
Running
提供诚实的用户反馈 - 承认官方 Space 访问限制
Browse files🎯 核心改进:
- 增强错误处理和详细的失败说明
- 识别 HTTP 403 和 WebSocket 连接被拒绝的问题
- 提供清晰的错误原因分析
✅ 诚实反馈:
- 承认官方 Space 限制了外部 API 访问
- 不再隐瞒或提供无意义的备用方案
- 明确说明当前技术限制
🔗 用户指导:
- 推荐直接访问官方 Space 界面使用
- 提供 GitHub 本地部署选项(20GB+ VRAM)
- 给出明确的替代方案链接
💡 用户体验:
- 清晰的状态消息和错误说明
- 实用的替代方案建议
- 不再浪费用户时间尝试无效的调用
这比提供虚假希望或无用的备用方案更诚实!
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
app.py
CHANGED
|
@@ -105,48 +105,80 @@ def call_huggingface_inference_api(video_file_path: str, text_prompt: str = "")
|
|
| 105 |
return None, f"❌ API 调用异常: {str(e)}"
|
| 106 |
|
| 107 |
def call_gradio_client_api(video_file_path: str, text_prompt: str = "") -> Tuple[Optional[str], str]:
|
| 108 |
-
"""使用 Gradio Client 调用官方 Space"""
|
| 109 |
try:
|
| 110 |
from gradio_client import Client
|
| 111 |
|
| 112 |
-
logger.info("
|
| 113 |
-
|
|
|
|
| 114 |
try:
|
| 115 |
client = Client("tencent/HunyuanVideo-Foley")
|
|
|
|
| 116 |
except Exception as e:
|
| 117 |
-
logger.
|
| 118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
-
logger.info(f"
|
| 121 |
logger.info(f"文本提示: '{text_prompt}'")
|
| 122 |
|
| 123 |
-
#
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
text_prompt, # text prompt
|
| 127 |
-
4.5, # guidance_scale
|
| 128 |
-
50, # inference_steps
|
| 129 |
-
1, # sample_nums
|
| 130 |
-
api_name="/process_inference" # 使用正确的 API 端点名称
|
| 131 |
-
)
|
| 132 |
|
| 133 |
-
|
|
|
|
| 134 |
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
else:
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
except ImportError:
|
| 146 |
-
return None, "❌
|
| 147 |
except Exception as e:
|
| 148 |
-
logger.error(f"
|
| 149 |
-
return None, f"❌
|
| 150 |
|
| 151 |
def create_fallback_audio(video_file_path: str, text_prompt: str) -> str:
|
| 152 |
"""创建备用演示音频(当 API 不可用时)- 完全兼容所有环境"""
|
|
@@ -294,9 +326,10 @@ def process_video_with_apis(video_file, text_prompt: str, guidance_scale: float,
|
|
| 294 |
status_messages.append(f"❌ 官方 Gradio Space: {gc_msg}")
|
| 295 |
logger.error(f"❌ 官方模型调用失败: {gc_msg}")
|
| 296 |
|
| 297 |
-
#
|
| 298 |
if not api_results:
|
| 299 |
-
status_messages.append("❌
|
|
|
|
| 300 |
|
| 301 |
# 构建详细状态消息
|
| 302 |
final_status = f"""🎵 HunyuanVideo-Foley 处理完成!
|
|
@@ -311,11 +344,12 @@ def process_video_with_apis(video_file, text_prompt: str, guidance_scale: float,
|
|
| 311 |
🎵 **生成结果**: {len(api_results)} 个音频文件
|
| 312 |
|
| 313 |
💡 **说明**:
|
| 314 |
-
•
|
| 315 |
-
•
|
| 316 |
-
•
|
| 317 |
|
| 318 |
-
🚀
|
|
|
|
| 319 |
|
| 320 |
return api_results, final_status
|
| 321 |
|
|
@@ -364,15 +398,15 @@ def create_api_interface():
|
|
| 364 |
# API Notice
|
| 365 |
gr.HTML("""
|
| 366 |
<div class="api-notice">
|
| 367 |
-
<strong>🔗
|
| 368 |
-
<br>•
|
| 369 |
<br>• 使用真正的 AI 模型生成 Foley 音频
|
| 370 |
<br>• 与视频内容完美同步的专业音效
|
| 371 |
<br><br>
|
| 372 |
-
<strong
|
| 373 |
-
<br>•
|
| 374 |
-
<br>•
|
| 375 |
-
<br>•
|
| 376 |
</div>
|
| 377 |
""")
|
| 378 |
|
|
@@ -439,12 +473,17 @@ def create_api_interface():
|
|
| 439 |
# Method info
|
| 440 |
gr.HTML("""
|
| 441 |
<div class="method-info">
|
| 442 |
-
<h3
|
| 443 |
-
<p><strong
|
| 444 |
-
<p><strong
|
| 445 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 446 |
<br>
|
| 447 |
-
<p><strong
|
| 448 |
</div>
|
| 449 |
""")
|
| 450 |
|
|
|
|
| 105 |
return None, f"❌ API 调用异常: {str(e)}"
|
| 106 |
|
| 107 |
def call_gradio_client_api(video_file_path: str, text_prompt: str = "") -> Tuple[Optional[str], str]:
|
| 108 |
+
"""使用 Gradio Client 调用官方 Space - 增强错误处理"""
|
| 109 |
try:
|
| 110 |
from gradio_client import Client
|
| 111 |
|
| 112 |
+
logger.info("尝试连接官方 HunyuanVideo-Foley Space...")
|
| 113 |
+
|
| 114 |
+
# 尝试连接客户端
|
| 115 |
try:
|
| 116 |
client = Client("tencent/HunyuanVideo-Foley")
|
| 117 |
+
logger.info("✅ 客户端连接成功")
|
| 118 |
except Exception as e:
|
| 119 |
+
logger.error(f"❌ 客户端初始化失败: {str(e)}")
|
| 120 |
+
if "403" in str(e):
|
| 121 |
+
return None, "❌ 官方 Space 访问被拒绝 (HTTP 403) - 可能需要特殊权限或 Space 正在维护"
|
| 122 |
+
elif "WebSocket" in str(e):
|
| 123 |
+
return None, "❌ WebSocket 连接失败 - 官方 Space 可能限制了外部访问"
|
| 124 |
+
else:
|
| 125 |
+
return None, f"❌ 无法连接到官方 Space: {str(e)}"
|
| 126 |
|
| 127 |
+
logger.info(f"准备处理视频: {os.path.basename(video_file_path)}")
|
| 128 |
logger.info(f"文本提示: '{text_prompt}'")
|
| 129 |
|
| 130 |
+
# 验证输入文件
|
| 131 |
+
if not os.path.exists(video_file_path):
|
| 132 |
+
return None, f"❌ 视频文件不存在: {video_file_path}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
+
file_size = os.path.getsize(video_file_path)
|
| 135 |
+
logger.info(f"视频文件大小: {file_size} bytes")
|
| 136 |
|
| 137 |
+
# 调用官方 Space API
|
| 138 |
+
try:
|
| 139 |
+
logger.info("🚀 开始调用官方模型...")
|
| 140 |
+
result = client.predict(
|
| 141 |
+
video_file_path,
|
| 142 |
+
text_prompt or "generate audio for this video",
|
| 143 |
+
4.5, # guidance_scale
|
| 144 |
+
50, # inference_steps
|
| 145 |
+
1, # sample_nums
|
| 146 |
+
api_name="/process_inference"
|
| 147 |
+
)
|
| 148 |
+
|
| 149 |
+
logger.info(f"✅ API 调用完成,结果类型: {type(result)}")
|
| 150 |
+
logger.info(f"结果内容: {str(result)[:200]}...")
|
| 151 |
+
|
| 152 |
+
# 处理返回结果
|
| 153 |
+
if result and isinstance(result, (list, tuple)) and len(result) > 0:
|
| 154 |
+
# 检查是否返回了音频文件
|
| 155 |
+
audio_file = result[0] if result[0] else None
|
| 156 |
+
|
| 157 |
+
if audio_file and os.path.exists(audio_file):
|
| 158 |
+
file_size = os.path.getsize(audio_file)
|
| 159 |
+
logger.info(f"✅ 获得音频文件: {os.path.basename(audio_file)} ({file_size} bytes)")
|
| 160 |
+
return audio_file, "✅ 成功调用官方模型生成音频!"
|
| 161 |
+
else:
|
| 162 |
+
logger.warning(f"❌ 返回的音频文件无效: {audio_file}")
|
| 163 |
+
return None, f"❌ 官方模型返回无效音频文件: {result}"
|
| 164 |
else:
|
| 165 |
+
logger.warning(f"❌ 官方模型返回空结果: {result}")
|
| 166 |
+
return None, f"❌ 官方模型返回空结果: {result}"
|
| 167 |
+
|
| 168 |
+
except Exception as api_error:
|
| 169 |
+
logger.error(f"❌ API 调用过程中失败: {str(api_error)}")
|
| 170 |
+
if "403" in str(api_error):
|
| 171 |
+
return None, "❌ API 调用被拒绝 - 官方 Space 可能限制了访问"
|
| 172 |
+
elif "timeout" in str(api_error).lower():
|
| 173 |
+
return None, "❌ API 调用超时 - 官方 Space 可能正忙或维护中"
|
| 174 |
+
else:
|
| 175 |
+
return None, f"❌ API 调用失败: {str(api_error)}"
|
| 176 |
|
| 177 |
except ImportError:
|
| 178 |
+
return None, "❌ 缺少 gradio-client 依赖"
|
| 179 |
except Exception as e:
|
| 180 |
+
logger.error(f"❌ 意外错误: {str(e)}")
|
| 181 |
+
return None, f"❌ 调用过程中出现意外错误: {str(e)}"
|
| 182 |
|
| 183 |
def create_fallback_audio(video_file_path: str, text_prompt: str) -> str:
|
| 184 |
"""创建备用演示音频(当 API 不可用时)- 完全兼容所有环境"""
|
|
|
|
| 326 |
status_messages.append(f"❌ 官方 Gradio Space: {gc_msg}")
|
| 327 |
logger.error(f"❌ 官方模型调用失败: {gc_msg}")
|
| 328 |
|
| 329 |
+
# 如果调用失败,提供详细说明
|
| 330 |
if not api_results:
|
| 331 |
+
status_messages.append("❌ 官方模型调用失败")
|
| 332 |
+
status_messages.append("💡 可能原因:官方 Space 限制外部访问、正在维护或需要特殊权限")
|
| 333 |
|
| 334 |
# 构建详细状态消息
|
| 335 |
final_status = f"""🎵 HunyuanVideo-Foley 处理完成!
|
|
|
|
| 344 |
🎵 **生成结果**: {len(api_results)} 个音频文件
|
| 345 |
|
| 346 |
💡 **说明**:
|
| 347 |
+
• 直接调用官方 tencent/HunyuanVideo-Foley Space
|
| 348 |
+
• 使用真正的 AI 模型进行音频生成
|
| 349 |
+
• 如果失败可能是官方 Space 访问限制
|
| 350 |
|
| 351 |
+
🚀 **官方模型**: https://huggingface.co/tencent/HunyuanVideo-Foley
|
| 352 |
+
🔗 **官方 Space**: https://huggingface.co/spaces/tencent/HunyuanVideo-Foley"""
|
| 353 |
|
| 354 |
return api_results, final_status
|
| 355 |
|
|
|
|
| 398 |
# API Notice
|
| 399 |
gr.HTML("""
|
| 400 |
<div class="api-notice">
|
| 401 |
+
<strong>🔗 官方模型调用尝试:</strong>
|
| 402 |
+
<br>• 尝试调用 tencent/HunyuanVideo-Foley 官方 Gradio Space
|
| 403 |
<br>• 使用真正的 AI 模型生成 Foley 音频
|
| 404 |
<br>• 与视频内容完美同步的专业音效
|
| 405 |
<br><br>
|
| 406 |
+
<strong>⚠️ 当前状态:</strong>
|
| 407 |
+
<br>• 官方 Space 可能限制了外部 API 访问 (HTTP 403)
|
| 408 |
+
<br>• 建议直接访问官方 Space 网页使用
|
| 409 |
+
<br>• 或考虑本地部署完整模型 (需要 20GB+ VRAM)
|
| 410 |
</div>
|
| 411 |
""")
|
| 412 |
|
|
|
|
| 473 |
# Method info
|
| 474 |
gr.HTML("""
|
| 475 |
<div class="method-info">
|
| 476 |
+
<h3>📋 使用说明和替代方案</h3>
|
| 477 |
+
<p><strong>🎯 当前尝试:</strong> 调用官方 Space API(可能被限制访问)</p>
|
| 478 |
+
<p><strong>✅ 推荐方案:</strong>
|
| 479 |
+
<a href="https://huggingface.co/spaces/tencent/HunyuanVideo-Foley" target="_blank">直接访问官方 Space</a>
|
| 480 |
+
</p>
|
| 481 |
+
<p><strong>💻 本地部署:</strong>
|
| 482 |
+
<a href="https://github.com/Tencent-Hunyuan/HunyuanVideo-Foley" target="_blank">GitHub 仓库</a>
|
| 483 |
+
(需要 20GB+ VRAM)
|
| 484 |
+
</p>
|
| 485 |
<br>
|
| 486 |
+
<p><strong>💡 说明:</strong> 由于官方 Space 访问限制,推荐直接使用官方界面获得最佳体验</p>
|
| 487 |
</div>
|
| 488 |
""")
|
| 489 |
|