Spaces:
Sleeping
Sleeping
Update app.py
Browse filesTry DeepSeek solution
app.py
CHANGED
@@ -4,6 +4,8 @@ import requests
|
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
|
7 |
from PIL import Image
|
8 |
|
9 |
from Gradio_UI import GradioUI
|
@@ -51,6 +53,23 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
51 |
except Exception as e:
|
52 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
@tool
|
55 |
def generate_image(description: str) -> Image:
|
56 |
"""A tool that generates an image from a text description.
|
@@ -62,10 +81,19 @@ def generate_image(description: str) -> Image:
|
|
62 |
name="image_generator",
|
63 |
description="Generate an image from a prompt"
|
64 |
)
|
65 |
-
#
|
66 |
-
|
67 |
-
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
|
71 |
|
|
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
+
from io import BytesIO
|
8 |
+
import base64
|
9 |
from PIL import Image
|
10 |
|
11 |
from Gradio_UI import GradioUI
|
|
|
53 |
except Exception as e:
|
54 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
55 |
|
56 |
+
# @tool
|
57 |
+
# def generate_image(description: str) -> Image:
|
58 |
+
# """A tool that generates an image from a text description.
|
59 |
+
# Args:
|
60 |
+
# description: A string representing the text description to generate an image of.
|
61 |
+
# """
|
62 |
+
# image_generation_tool = Tool.from_space(
|
63 |
+
# "black-forest-labs/FLUX.1-schnell",
|
64 |
+
# name="image_generator",
|
65 |
+
# description="Generate an image from a prompt"
|
66 |
+
# )
|
67 |
+
# # image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
68 |
+
# image: Image = image_generation_tool(description)
|
69 |
+
# # return f"Image generated for prompt: {description}."
|
70 |
+
# return image
|
71 |
+
|
72 |
+
|
73 |
@tool
|
74 |
def generate_image(description: str) -> Image:
|
75 |
"""A tool that generates an image from a text description.
|
|
|
81 |
name="image_generator",
|
82 |
description="Generate an image from a prompt"
|
83 |
)
|
84 |
+
# Generate the image
|
85 |
+
pil_image: Image = image_generation_tool(description)
|
86 |
+
|
87 |
+
# Convert image to bytes
|
88 |
+
buffered = BytesIO()
|
89 |
+
pil_image.save(buffered, format="PNG")
|
90 |
+
buffered.seek(0)
|
91 |
+
|
92 |
+
# Encode as base64
|
93 |
+
img_base64 = base64.b64encode(buffered.read()).decode()
|
94 |
+
|
95 |
+
# Return as Markdown image
|
96 |
+
return f""
|
97 |
|
98 |
|
99 |
|