File size: 1,825 Bytes
ff0650d
9b5b26a
 
c19d193
6aae614
9b5b26a
 
 
5b59a99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9b5b26a
 
4bd043e
5b59a99
4bd043e
 
5b59a99
4bd043e
 
5b59a99
4bd043e
9b5b26a
 
 
5b59a99
9b5b26a
5b59a99
8c01ffb
 
5b59a99
3e057c1
 
ae7a494
5b59a99
e121372
ff0650d
5b59a99
 
ff0650d
8c01ffb
ff0650d
5b59a99
 
 
ff0650d
 
5b59a99
8c01ffb
8fe992b
ff0650d
5b59a99
ff0650d
 
 
 
8c01ffb
ff0650d
b9f6f2b
5b59a99
861422e
8fe992b
 
9b5b26a
5b59a99
8c01ffb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
import datetime
import pytz
import yaml
from tools.final_answer import FinalAnswerTool
from Gradio_UI import GradioUI


# Load HF image generation tool
hf_image_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)


@tool
def generate_image(prompt: str) -> str:
    """
    Generate an image from a text prompt.

    Args:
        prompt (str): Description of the image.

    Returns:
        str: File path of the generated image.
    """
    img = hf_image_tool(prompt=prompt)
    path = "/tmp/generated_image.png"
    img.save(path)
    return path


@tool
def get_current_time_in_timezone(timezone: str) -> str:
    """
    Get current time for a timezone.

    Args:
        timezone (str): Example 'Asia/Kolkata'.

    Returns:
        str: Current time in that timezone.
    """
    try:
        tz = pytz.timezone(timezone)
        local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
        return f"Time in {timezone}: {local_time}"
    except Exception as e:
        return str(e)


# Mandatory final answer tool
final_answer = FinalAnswerTool()


# LLM for reasoning
model = HfApiModel(
    model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
    max_tokens=2048,
    temperature=0.5
)


# Prompt templates
with open("prompts.yaml", "r") as f:
    prompt_templates = yaml.safe_load(f)


# Agent
agent = CodeAgent(
    model=model,
    tools=[
        generate_image,
        DuckDuckGoSearchTool(),
        get_current_time_in_timezone,
        final_answer
    ],
    max_steps=6,
    verbosity_level=2,
    name="multitool_agent",
    description="Agent that can generate images, search the web, and get timezone time.",
    prompt_templates=prompt_templates
)


# Launch UI
GradioUI(agent).launch()