Added image generation tool.
Browse files- Gradio_UI.py +6 -5
- app.py +10 -7
Gradio_UI.py
CHANGED
@@ -24,7 +24,6 @@ from smolagents.agents import ActionStep, MultiStepAgent
|
|
24 |
from smolagents.memory import MemoryStep
|
25 |
from smolagents.utils import _is_package_available
|
26 |
|
27 |
-
|
28 |
def pull_messages_from_step(
|
29 |
step_log: MemoryStep,
|
30 |
):
|
@@ -156,17 +155,19 @@ def stream_to_gradio(
|
|
156 |
final_answer = step_log # Last log is the run's final_answer
|
157 |
final_answer = handle_agent_output_types(final_answer)
|
158 |
|
159 |
-
if isinstance(final_answer, AgentText):
|
160 |
yield gr.ChatMessage(
|
161 |
role="assistant",
|
162 |
content=f"**Final answer:**\n{final_answer.to_string()}\n",
|
163 |
)
|
164 |
-
elif isinstance(final_answer, AgentImage):
|
|
|
165 |
yield gr.ChatMessage(
|
166 |
role="assistant",
|
167 |
-
content=
|
|
|
168 |
)
|
169 |
-
elif isinstance(final_answer, AgentAudio):
|
170 |
yield gr.ChatMessage(
|
171 |
role="assistant",
|
172 |
content={"path": final_answer.to_string(), "mime_type": "audio/wav"},
|
|
|
24 |
from smolagents.memory import MemoryStep
|
25 |
from smolagents.utils import _is_package_available
|
26 |
|
|
|
27 |
def pull_messages_from_step(
|
28 |
step_log: MemoryStep,
|
29 |
):
|
|
|
155 |
final_answer = step_log # Last log is the run's final_answer
|
156 |
final_answer = handle_agent_output_types(final_answer)
|
157 |
|
158 |
+
if isinstance(final_answer.final_answer, AgentText):
|
159 |
yield gr.ChatMessage(
|
160 |
role="assistant",
|
161 |
content=f"**Final answer:**\n{final_answer.to_string()}\n",
|
162 |
)
|
163 |
+
elif isinstance(final_answer.final_answer, AgentImage):
|
164 |
+
|
165 |
yield gr.ChatMessage(
|
166 |
role="assistant",
|
167 |
+
content=gr.Image(str(final_answer.final_answer)),
|
168 |
+
metadata={"mime_type": "image/png"},
|
169 |
)
|
170 |
+
elif isinstance(final_answer.final_answer, AgentAudio):
|
171 |
yield gr.ChatMessage(
|
172 |
role="assistant",
|
173 |
content={"path": final_answer.to_string(), "mime_type": "audio/wav"},
|
app.py
CHANGED
@@ -7,7 +7,7 @@ from tools.final_answer import FinalAnswerTool
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
-
# Below is an example of a tool that does nothing. Amaze us with your creativity
|
11 |
@tool
|
12 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
@@ -40,13 +40,12 @@ final_answer = FinalAnswerTool()
|
|
40 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
41 |
|
42 |
model = HfApiModel(
|
43 |
-
max_tokens=2096,
|
44 |
-
temperature=0.5,
|
45 |
-
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
|
46 |
-
custom_role_conversions=None
|
47 |
)
|
48 |
|
49 |
-
|
50 |
# Import tool from Hub
|
51 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
52 |
|
@@ -55,7 +54,11 @@ with open("prompts.yaml", 'r') as stream:
|
|
55 |
|
56 |
demo = CodeAgent(
|
57 |
model=model,
|
58 |
-
tools=[
|
|
|
|
|
|
|
|
|
59 |
max_steps=6,
|
60 |
verbosity_level=1,
|
61 |
grammar=None,
|
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
+
# Below is an example of a tool that does nothing. Amaze us with your creativity!
|
11 |
@tool
|
12 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
|
|
40 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
41 |
|
42 |
model = HfApiModel(
|
43 |
+
max_tokens=2096,
|
44 |
+
temperature=0.5,
|
45 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
|
46 |
+
custom_role_conversions=None
|
47 |
)
|
48 |
|
|
|
49 |
# Import tool from Hub
|
50 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
51 |
|
|
|
54 |
|
55 |
demo = CodeAgent(
|
56 |
model=model,
|
57 |
+
tools=[
|
58 |
+
get_current_time_in_timezone,
|
59 |
+
image_generation_tool,
|
60 |
+
final_answer
|
61 |
+
], ## add your tools here (don't remove final answer)
|
62 |
max_steps=6,
|
63 |
verbosity_level=1,
|
64 |
grammar=None,
|