osmahus commited on
Commit
7f2920e
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -17
app.py CHANGED
@@ -1,4 +1,4 @@
1
- from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
2
  import datetime
3
  import requests
4
  import pytz
@@ -6,17 +6,42 @@ import yaml
6
  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
14
- """A tool that does nothing yet
 
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -37,25 +62,32 @@ def get_current_time_in_timezone(timezone: str) -> str:
37
  final_answer = FinalAnswerTool()
38
 
39
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
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
 
53
- with open("prompts.yaml", 'r') as stream:
 
 
 
54
  prompt_templates = yaml.safe_load(stream)
55
-
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer], ## add your tools here (don't remove final answer)
 
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
@@ -66,4 +98,4 @@ agent = CodeAgent(
66
  )
67
 
68
 
69
- GradioUI(agent).launch()
 
1
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
2
  import datetime
3
  import requests
4
  import pytz
 
6
  from tools.final_answer import FinalAnswerTool
7
 
8
  from Gradio_UI import GradioUI
9
+ import os
10
+
11
+ from PIL import Image
12
+ import requests
13
+ from io import BytesIO
14
+
15
+
16
+ print(os.getcwd())
17
+ current_directory = os.path.dirname(os.path.abspath(__file__))
18
+
19
 
20
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
21
  @tool
22
+ # it's import to specify the return type
23
+ def get_random_image(width: int, height: int) -> Image.Image:
24
+ """Retrieve a random image with the desired dimensions.
25
+
26
  Args:
27
+ width: Desired width of the image.
28
+ height: Desired height of the image.
29
  """
30
+ if width <= 0 or height <= 0:
31
+ raise ValueError("Width and height must be positive integers.")
32
+
33
+ # Generate the URL for a random image
34
+ url = f"https://picsum.photos/{width}/{height}"
35
+
36
+ # Download the image
37
+ response = requests.get(url)
38
+ if response.status_code == 200:
39
+ # Open the image
40
+ image = Image.open(BytesIO(response.content))
41
+ return image
42
+ else:
43
+ raise Exception("Failed to download the image.")
44
+
45
 
46
  @tool
47
  def get_current_time_in_timezone(timezone: str) -> str:
 
62
  final_answer = FinalAnswerTool()
63
 
64
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
65
+ # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
66
+ # model_id='Qwen/Qwen2.5-Coder-32B-Instruct'
67
 
68
  model = HfApiModel(
69
+ max_tokens=2096,
70
+ temperature=0.5,
71
+ # it is possible that this model may be overloaded
72
+ model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud',
73
+ custom_role_conversions=None,
74
  )
75
 
76
 
77
  # Import tool from Hub
78
+ image_generation_tool = load_tool(
79
+ "agents-course/text-to-image", trust_remote_code=True)
80
 
81
+ prompts_file = f"prompts.yaml"
82
+ prompts_path = f"{current_directory}/{prompts_file}"
83
+
84
+ with open(prompts_path, 'r') as stream:
85
  prompt_templates = yaml.safe_load(stream)
86
+
87
  agent = CodeAgent(
88
  model=model,
89
+ # add your tools here (don't remove final answer)
90
+ tools=[get_random_image, get_current_time_in_timezone, final_answer],
91
  max_steps=6,
92
  verbosity_level=1,
93
  grammar=None,
 
98
  )
99
 
100
 
101
+ GradioUI(agent).launch()