Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,13 @@
|
|
1 |
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
2 |
import datetime
|
3 |
-
import pytz
|
4 |
-
import yaml
|
5 |
from tools.final_answer import FinalAnswerTool
|
6 |
from Gradio_UI import GradioUI
|
7 |
|
8 |
-
# Define
|
9 |
@tool
|
10 |
def get_current_time_in_timezone(timezone: str) -> str:
|
11 |
-
"""Fetches the current local time in a specified timezone.
|
12 |
-
Args:
|
13 |
-
timezone: A valid timezone string (e.g., 'America/New_York').
|
14 |
-
"""
|
15 |
try:
|
16 |
tz = pytz.timezone(timezone)
|
17 |
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
@@ -19,37 +15,61 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
19 |
except Exception as e:
|
20 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
# Load final answer tool
|
23 |
final_answer = FinalAnswerTool()
|
24 |
|
25 |
-
# Define the model
|
26 |
model = HfApiModel(
|
27 |
max_tokens=2096,
|
28 |
-
temperature=0.
|
29 |
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
30 |
custom_role_conversions=None,
|
31 |
)
|
32 |
|
33 |
-
#
|
34 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
35 |
|
36 |
# Load prompt templates
|
37 |
with open("prompts.yaml", 'r') as stream:
|
38 |
prompt_templates = yaml.safe_load(stream)
|
39 |
|
40 |
-
# Create the
|
41 |
agent = CodeAgent(
|
42 |
model=model,
|
43 |
-
tools=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
max_steps=6,
|
45 |
verbosity_level=1,
|
46 |
grammar=None,
|
47 |
planning_interval=None,
|
48 |
-
name="
|
49 |
-
description="An AI assistant capable of
|
50 |
prompt_templates=prompt_templates
|
51 |
)
|
52 |
|
53 |
# Launch UI
|
54 |
GradioUI(agent).launch()
|
55 |
|
|
|
|
1 |
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
2 |
import datetime
|
3 |
+
import pytz\import yaml
|
|
|
4 |
from tools.final_answer import FinalAnswerTool
|
5 |
from Gradio_UI import GradioUI
|
6 |
|
7 |
+
# Define tool for fetching current time in a timezone
|
8 |
@tool
|
9 |
def get_current_time_in_timezone(timezone: str) -> str:
|
10 |
+
"""Fetches the current local time in a specified timezone."""
|
|
|
|
|
|
|
11 |
try:
|
12 |
tz = pytz.timezone(timezone)
|
13 |
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
|
|
15 |
except Exception as e:
|
16 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
17 |
|
18 |
+
# Define tool for AI research paper search
|
19 |
+
@tool
|
20 |
+
def fetch_ai_research_papers(query: str) -> str:
|
21 |
+
"""Fetches recent AI research papers based on the query."""
|
22 |
+
search_tool = DuckDuckGoSearchTool()
|
23 |
+
results = search_tool.search(f"AI research paper {query}")
|
24 |
+
return f"Top AI research papers on {query}: {results}"
|
25 |
+
|
26 |
+
# Define tool for AI news updates
|
27 |
+
@tool
|
28 |
+
def fetch_ai_news() -> str:
|
29 |
+
"""Fetches the latest AI news updates."""
|
30 |
+
search_tool = DuckDuckGoSearchTool()
|
31 |
+
results = search_tool.search("latest AI news")
|
32 |
+
return f"Latest AI news updates: {results}"
|
33 |
+
|
34 |
# Load final answer tool
|
35 |
final_answer = FinalAnswerTool()
|
36 |
|
37 |
+
# Define the model for human-like responses
|
38 |
model = HfApiModel(
|
39 |
max_tokens=2096,
|
40 |
+
temperature=0.7, # Increased temperature for more human-like responses
|
41 |
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
42 |
custom_role_conversions=None,
|
43 |
)
|
44 |
|
45 |
+
# Load text-to-image generation tool
|
46 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
47 |
|
48 |
# Load prompt templates
|
49 |
with open("prompts.yaml", 'r') as stream:
|
50 |
prompt_templates = yaml.safe_load(stream)
|
51 |
|
52 |
+
# Create the AI Assistant Agent
|
53 |
agent = CodeAgent(
|
54 |
model=model,
|
55 |
+
tools=[
|
56 |
+
final_answer,
|
57 |
+
DuckDuckGoSearchTool(),
|
58 |
+
get_current_time_in_timezone,
|
59 |
+
fetch_ai_research_papers,
|
60 |
+
fetch_ai_news,
|
61 |
+
image_generation_tool
|
62 |
+
],
|
63 |
max_steps=6,
|
64 |
verbosity_level=1,
|
65 |
grammar=None,
|
66 |
planning_interval=None,
|
67 |
+
name="AI Research Assistant",
|
68 |
+
description="An AI assistant capable of answering queries, fetching AI research, news, generating images, and interacting naturally.",
|
69 |
prompt_templates=prompt_templates
|
70 |
)
|
71 |
|
72 |
# Launch UI
|
73 |
GradioUI(agent).launch()
|
74 |
|
75 |
+
|