Abdul-samet commited on
Commit
c542cd0
·
verified ·
1 Parent(s): 1eca432

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -12
app.py CHANGED
@@ -51,6 +51,7 @@ custom_role_conversions=None,
51
 
52
  # Import tool from Hub
53
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
 
54
  @tool
55
  def image_open(prompt: str) -> None:
56
  """Prompta göre görüntü üretir ve resmi açar.
@@ -59,21 +60,21 @@ def image_open(prompt: str) -> None:
59
  prompt:Bir prompt alır(örnek:a cat image)
60
 
61
  """
62
- # Resmi üret
63
- result = image_generation_tool(prompt=prompt)
64
-
65
- # Base64 string al
66
- img_base64 = result["images"][0]
67
-
68
- # Base64 → byte
69
- img_bytes = base64.b64decode(img_base64)
70
 
71
- # Byte PIL Image
72
- img = Image.open(BytesIO(img_bytes))
 
73
 
74
- # resmi
75
- img.show()
 
 
76
 
 
 
77
  return None
78
 
79
 
 
51
 
52
  # Import tool from Hub
53
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
54
+
55
  @tool
56
  def image_open(prompt: str) -> None:
57
  """Prompta göre görüntü üretir ve resmi açar.
 
60
  prompt:Bir prompt alır(örnek:a cat image)
61
 
62
  """
63
+
64
+ # Tool’u çağır → zaten bir PIL Image döndürüyor
65
+ img = image_generation_tool(prompt=prompt)
 
 
 
 
 
66
 
67
+ # Eğer tool bir dict gibi dönerse ona göre ele alalım
68
+ if isinstance(img, dict) and "images" in img:
69
+ img = img["images"][0] # ama büyük ihtimalle buna gerek kalmaz
70
 
71
+ # Eğer img gerçekten bir PIL.Image ise:
72
+ if hasattr(img, "show"):
73
+ img.show()
74
+ return None
75
 
76
+ # Eğer hâlâ değilse güvenli bir hata mesajı
77
+ print("image_generation_tool beklenmeyen bir format döndürdü:", type(img))
78
  return None
79
 
80