test_nanobanana_simple.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. """
  2. 简单测试脚本 - 测试Nano Banana图像生成与编辑工具
  3. """
  4. import sys
  5. from pathlib import Path
  6. # 添加项目根目录到路径
  7. project_root = Path(__file__).parent.parent.parent
  8. sys.path.insert(0, str(project_root))
  9. from src.components.tools.nanobanana_tools import nano_banana_generate_image
  10. # 真实测试图片
  11. REAL_IMAGE_URL = "https://res.cybertogether.net/crawler/image/097f43c71d746f7bd10f62df64222459.jpeg"
  12. def test_extract_mango():
  13. """测试提取左上芒果"""
  14. print("\n" + "=" * 70)
  15. print("🎨 Nano Banana图像编辑工具 - 提取左上芒果测试")
  16. print("=" * 70)
  17. print(f"\n图片URL: {REAL_IMAGE_URL}\n")
  18. test_prompt = "Extract the mango in the upper left corner of the image as a separate image"
  19. print(f"📸 测试任务: {test_prompt}")
  20. print("-" * 70)
  21. result = nano_banana_generate_image(
  22. prompt=test_prompt,
  23. images=REAL_IMAGE_URL
  24. )
  25. print(f"\n结果:")
  26. print(f" {result}")
  27. print()
  28. # 判断是否成功
  29. if result.startswith("http"):
  30. print("✅ 成功! 返回了图片URL")
  31. elif "失败" in result or "超时" in result or "错误" in result:
  32. print("❌ 失败! API服务出现问题")
  33. print("\n💡 可能的原因:")
  34. print(" - Nano Banana后端服务超时")
  35. print(" - API服务器负载过高")
  36. print(" - 网络连接问题")
  37. else:
  38. print("⚠️ 未知状态")
  39. print("\n" + "=" * 70)
  40. if __name__ == "__main__":
  41. try:
  42. test_extract_mango()
  43. except Exception as e:
  44. print(f"\n❌ 发生错误: {str(e)}")
  45. import traceback
  46. traceback.print_exc()