MD112575 commited on
Commit
e768d75
·
verified ·
1 Parent(s): f5518c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -47
app.py CHANGED
@@ -1,68 +1,35 @@
1
- from smolagents import CodeAgent, HfApiModel, load_tool, tool
2
- import datetime
3
- import pytz
4
  import yaml
5
- import os
6
-
7
  from tools.final_answer import FinalAnswerTool
8
  from Gradio_UI import GradioUI
9
 
10
-
11
- # -------------------- TOOLS --------------------
12
-
13
- @tool
14
- def get_current_time_in_timezone(timezone: str) -> str:
15
- """Fetch current time in a timezone.
16
- Args:
17
- timezone: e.g. 'Asia/Kolkata'
18
- """
19
- try:
20
- tz = pytz.timezone(timezone)
21
- local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
22
- return f"The current local time in {timezone} is: {local_time}"
23
- except Exception as e:
24
- return f"Error fetching time: {str(e)}"
25
-
26
-
27
- # ✅ USE HF BUILT-IN IMAGE TOOL (more stable)
28
  image_generation_tool = load_tool(
29
  "agents-course/text-to-image",
30
  trust_remote_code=True
31
  )
32
 
33
-
34
- # -------------------- MODEL --------------------
35
-
36
  final_answer = FinalAnswerTool()
37
 
 
38
  model = HfApiModel(
39
- max_tokens=2096,
40
- temperature=0.5,
41
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
42
  )
43
 
 
 
 
44
 
45
- # -------------------- PROMPTS --------------------
46
-
47
- with open("prompts.yaml", 'r') as stream:
48
- prompt_templates = yaml.safe_load(stream)
49
-
50
-
51
- # -------------------- AGENT --------------------
52
-
53
  agent = CodeAgent(
54
  model=model,
55
- tools=[
56
- final_answer,
57
- get_current_time_in_timezone,
58
- image_generation_tool # ✅ this works reliably
59
- ],
60
- max_steps=6,
61
  verbosity_level=1,
62
- prompt_templates=prompt_templates
63
  )
64
 
65
-
66
- # -------------------- UI --------------------
67
-
68
  GradioUI(agent).launch()
 
1
+ from smolagents import CodeAgent, HfApiModel, load_tool
 
 
2
  import yaml
 
 
3
  from tools.final_answer import FinalAnswerTool
4
  from Gradio_UI import GradioUI
5
 
6
+ # -------- TOOLS --------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  image_generation_tool = load_tool(
8
  "agents-course/text-to-image",
9
  trust_remote_code=True
10
  )
11
 
 
 
 
12
  final_answer = FinalAnswerTool()
13
 
14
+ # -------- MODEL --------
15
  model = HfApiModel(
16
+ model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
17
+ max_tokens=1024,
18
+ temperature=0.3,
19
  )
20
 
21
+ # -------- PROMPTS --------
22
+ with open("prompts.yaml", "r") as f:
23
+ prompt_templates = yaml.safe_load(f)
24
 
25
+ # -------- AGENT --------
 
 
 
 
 
 
 
26
  agent = CodeAgent(
27
  model=model,
28
+ tools=[final_answer, image_generation_tool],
29
+ max_steps=4,
 
 
 
 
30
  verbosity_level=1,
31
+ prompt_templates=prompt_templates,
32
  )
33
 
34
+ # -------- UI --------
 
 
35
  GradioUI(agent).launch()