File size: 2,366 Bytes
319b734
9b5b26a
 
8d6ebae
 
de384ab
8fe992b
9b5b26a
319b734
 
5e9c8f5
9b5b26a
62d347f
 
 
 
9b5b26a
319b734
 
 
 
 
8d6ebae
319b734
8d6ebae
de384ab
9b5b26a
 
319b734
62d347f
 
 
 
 
5e9c8f5
62d347f
 
 
 
8c01ffb
87c11c6
319b734
8d6ebae
de384ab
319b734
 
 
8d6ebae
de384ab
 
62d347f
319b734
 
8d6ebae
62d347f
319b734
62d347f
970cac2
319b734
8d6ebae
319b734
 
 
 
 
 
 
 
 
62d347f
319b734
8d6ebae
62d347f
 
319b734
970cac2
319b734
 
 
62d347f
319b734
8fe992b
de384ab
319b734
 
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
85
from smolagents import CodeAgent, InferenceClientModel, load_tool, tool
import datetime
import pytz
from tools.final_answer import FinalAnswerTool
from Gradio_UI import GradioUI


@tool
def get_current_time_in_timezone(timezone: str) -> str:
    """Get the current local time in the requested timezone.

    Args:
        timezone: IANA timezone name (e.g. 'Asia/Kolkata', 'America/New_York', 'Europe/London')

    Returns:
        Human-readable string with current time or error message
    """
    try:
        tz = pytz.timezone(timezone)
        now = datetime.datetime.now(tz)
        return f"Current time in **{timezone}**: {now:%Y-%m-%d %H:%M:%S %Z}"
    except pytz.exceptions.UnknownTimeZoneError:
        return f"Unknown timezone: '{timezone}' — please use a valid IANA name"
    except Exception as e:
        return f"Error: {str(e)}"


@tool
def my_custom_tool(arg1: str, arg2: int) -> str:
    """Placeholder custom tool — replace with real logic as needed.

    Args:
        arg1: some text input (e.g. a name, description, or keyword)
        arg2: some integer input (e.g. a count, year, or multiplier)

    Returns:
        Demonstration response string
    """
    return f"Tool called → arg1 = {arg1!r} | arg2 = {arg2} → What would you like to build?"


def main():
    final_answer_tool = FinalAnswerTool()

    model = InferenceClientModel(
        model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
        temperature=0.5,
        max_tokens=2048,
    )

    # Optional: text-to-image tool
    image_tool = None
    try:
        image_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
        print("Text-to-image tool loaded")
    except Exception as e:
        print(f"Text-to-image load failed: {e}")

    tools = [
        final_answer_tool,
        get_current_time_in_timezone,
        my_custom_tool,
    ]
    if image_tool is not None:
        tools.append(image_tool)

    agent = CodeAgent(
        tools=tools,
        model=model,
        max_steps=10,
        verbosity_level=1,
        stream_outputs=True,
        # planning_interval=4,           # optional
        # prompt_templates=...           # only if you really need custom prompts
    )

    GradioUI(agent).launch(
        server_name="0.0.0.0",
        server_port=7860,
        # share=True,
    )


if __name__ == "__main__":
    main()