Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
# Base64 string al
|
| 66 |
-
img_base64 = result["images"][0]
|
| 67 |
-
|
| 68 |
-
# Base64 → byte
|
| 69 |
-
img_bytes = base64.b64decode(img_base64)
|
| 70 |
|
| 71 |
-
#
|
| 72 |
-
img
|
|
|
|
| 73 |
|
| 74 |
-
#
|
| 75 |
-
img
|
|
|
|
|
|
|
| 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 |
|