| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- """
- 简单测试脚本 - 测试Nano Banana图像生成与编辑工具
- """
- import sys
- from pathlib import Path
- # 添加项目根目录到路径
- project_root = Path(__file__).parent.parent.parent
- sys.path.insert(0, str(project_root))
- from src.components.tools.nanobanana_tools import nano_banana_generate_image
- # 真实测试图片
- REAL_IMAGE_URL = "https://res.cybertogether.net/crawler/image/097f43c71d746f7bd10f62df64222459.jpeg"
- def test_extract_mango():
- """测试提取左上芒果"""
- print("\n" + "=" * 70)
- print("🎨 Nano Banana图像编辑工具 - 提取左上芒果测试")
- print("=" * 70)
- print(f"\n图片URL: {REAL_IMAGE_URL}\n")
- test_prompt = "Extract the mango in the upper left corner of the image as a separate image"
- print(f"📸 测试任务: {test_prompt}")
- print("-" * 70)
- result = nano_banana_generate_image(
- prompt=test_prompt,
- images=REAL_IMAGE_URL
- )
- print(f"\n结果:")
- print(f" {result}")
- print()
- # 判断是否成功
- if result.startswith("http"):
- print("✅ 成功! 返回了图片URL")
- elif "失败" in result or "超时" in result or "错误" in result:
- print("❌ 失败! API服务出现问题")
- print("\n💡 可能的原因:")
- print(" - Nano Banana后端服务超时")
- print(" - API服务器负载过高")
- print(" - 网络连接问题")
- else:
- print("⚠️ 未知状态")
- print("\n" + "=" * 70)
- if __name__ == "__main__":
- try:
- test_extract_mango()
- except Exception as e:
- print(f"\n❌ 发生错误: {str(e)}")
- import traceback
- traceback.print_exc()
|