Dave67350 commited on
Commit
3367554
·
verified ·
1 Parent(s): 5ff49c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -99
app.py CHANGED
@@ -1,101 +1,5 @@
1
- from smolagents import CodeAgent, HfApiModel, load_tool, tool, VisitWebpageTool
2
- import datetime
3
- import requests
4
- import pytz
5
- import yaml
6
- from tools.final_answer import FinalAnswerTool
7
- from duckduckgo_search import DDGS
8
  from tools.ai_act_generator import launch_step_by_step_ui
9
- #from tools.ai_act_generator import generate_ai_act_register
10
-
11
-
12
-
13
- from Gradio_UI import GradioUI
14
-
15
-
16
- # Below is an example of a tool that does nothing. Amaze us with your creativity !
17
- @tool
18
- def my_custom_tool(arg1: str, arg2: int) -> str: # it's important to specify the return type
19
- """A tool that does nothing yet
20
- Args:
21
- arg1: the first argument
22
- arg2: the second argument
23
- """
24
- return "What magic will you build ?"
25
-
26
- @tool
27
- def get_current_time_in_timezone(timezone: str) -> str:
28
- """A tool that fetches the current local time in a specified timezone.
29
- Args:
30
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
31
- """
32
- try:
33
- # Create timezone object
34
- tz = pytz.timezone(timezone)
35
- # Get current time in that timezone
36
- local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
37
- return f"The current local time in {timezone} is: {local_time}"
38
- except Exception as e:
39
- return f"Error fetching time for timezone '{timezone}': {str(e)}"
40
-
41
- @tool
42
- def ai_act_search_tool(query: str, max_results: int = 5) -> list:
43
- """Searches for highly relevant articles on the AI Act using DuckDuckGo.
44
- Args:
45
- query: The search query.
46
- max_results: The maximum number of results to return.
47
- Returns:
48
- A list of URLs to relevant articles.
49
- """
50
- with DDGS() as ddgs:
51
- search_results = ddgs.text(query + " AI Act", max_results)
52
- return [{"title": result["title"], "link": result["href"]} for result in search_results] if search_results else ["No relevant articles found."]
53
-
54
-
55
-
56
- #@tool
57
- #def fetch_url(url: str) -> str:
58
- # """Fetches the content of a given URL and returns the raw text.
59
- # Args:
60
- # url: The URL to fetch content from.
61
- # Returns:
62
- # The raw text content of the page, or an error message if fetching fails.
63
- # """
64
- # response = requests.get(url)
65
- # return response.text if response.status_code == 200 else "Failed to fetch content."
66
-
67
- final_answer = FinalAnswerTool()
68
- visit_webpage = VisitWebpageTool()
69
-
70
-
71
- # 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:
72
- # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
73
-
74
- model = HfApiModel(
75
- max_tokens=2096,
76
- temperature=0.5,
77
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct', # it is possible that this model may be overloaded
78
- custom_role_conversions=None,
79
- )
80
-
81
- # Import tool from Hub
82
- image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
83
-
84
- with open("prompts.yaml", 'r') as stream:
85
- prompt_templates = yaml.safe_load(stream)
86
-
87
- agent = CodeAgent(
88
- model=model,
89
- tools=[final_answer, image_generation_tool, ai_act_search_tool, visit_webpage, launch_step_by_step_ui ], # Added AI Act search tool
90
- max_steps=6,
91
- verbosity_level=1,
92
- grammar=None,
93
- planning_interval=None,
94
- name=None,
95
- description=None,
96
- prompt_templates=prompt_templates
97
- )
98
-
99
- GradioUI(agent).launch()
100
-
101
 
 
 
 
1
+ # app.py
 
 
 
 
 
 
2
  from tools.ai_act_generator import launch_step_by_step_ui
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
+ if __name__ == "__main__":
5
+ launch_step_by_step_ui()