Spaces:
Running
Running
Update app.py
Browse files
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
|
@@ -7,47 +7,66 @@ 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
|
13 |
-
|
14 |
-
|
|
|
15 |
Args:
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
18 |
"""
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
@tool
|
22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
23 |
-
"""
|
|
|
|
|
24 |
Args:
|
25 |
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
|
|
|
|
|
|
26 |
"""
|
27 |
try:
|
28 |
-
# Create timezone object
|
29 |
tz = pytz.timezone(timezone)
|
30 |
-
# Get current time in that timezone
|
31 |
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
32 |
return f"The current local time in {timezone} is: {local_time}"
|
33 |
except Exception as e:
|
34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
35 |
|
36 |
-
|
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'
|
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:
|
@@ -55,7 +74,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
55 |
|
56 |
agent = CodeAgent(
|
57 |
model=model,
|
58 |
-
tools=[final_answer],
|
59 |
max_steps=6,
|
60 |
verbosity_level=1,
|
61 |
grammar=None,
|
@@ -65,5 +84,4 @@ agent = CodeAgent(
|
|
65 |
prompt_templates=prompt_templates
|
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
|
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
|
|
10 |
@tool
|
11 |
+
def simulate_ai_debate(topic: str, rounds: int = 3) -> str:
|
12 |
+
"""
|
13 |
+
A tool that simulates a debate between two AI models (AI Alpha and AI Beta) on a given topic.
|
14 |
+
|
15 |
Args:
|
16 |
+
topic: The subject of the discussion.
|
17 |
+
rounds: Number of exchange rounds between the two AI models.
|
18 |
+
|
19 |
+
Returns:
|
20 |
+
A transcript of the simulated debate.
|
21 |
"""
|
22 |
+
transcript = f"Debate Topic: {topic}\n\n"
|
23 |
+
|
24 |
+
for i in range(rounds):
|
25 |
+
# AI Alpha's turn
|
26 |
+
alpha_prompt = (
|
27 |
+
f"Round {i+1} - You are AI Alpha. Present your argument on the topic '{topic}' "
|
28 |
+
f"given the following discussion transcript:\n\n{transcript}\nYour response:"
|
29 |
+
)
|
30 |
+
alpha_response = model.generate(prompt=alpha_prompt)
|
31 |
+
transcript += f"AI Alpha: {alpha_response}\n\n"
|
32 |
+
|
33 |
+
# AI Beta's turn
|
34 |
+
beta_prompt = (
|
35 |
+
f"Round {i+1} - You are AI Beta. Provide your counterargument on the topic '{topic}' "
|
36 |
+
f"given the following discussion transcript:\n\n{transcript}\nYour response:"
|
37 |
+
)
|
38 |
+
beta_response = model.generate(prompt=beta_prompt)
|
39 |
+
transcript += f"AI Beta: {beta_response}\n\n"
|
40 |
+
|
41 |
+
return transcript
|
42 |
|
43 |
@tool
|
44 |
def get_current_time_in_timezone(timezone: str) -> str:
|
45 |
+
"""
|
46 |
+
A tool that fetches the current local time in a specified timezone.
|
47 |
+
|
48 |
Args:
|
49 |
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
50 |
+
|
51 |
+
Returns:
|
52 |
+
A string with the current local time or an error message.
|
53 |
"""
|
54 |
try:
|
|
|
55 |
tz = pytz.timezone(timezone)
|
|
|
56 |
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
57 |
return f"The current local time in {timezone} is: {local_time}"
|
58 |
except Exception as e:
|
59 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
60 |
|
|
|
61 |
final_answer = FinalAnswerTool()
|
62 |
|
|
|
|
|
|
|
63 |
model = HfApiModel(
|
64 |
+
max_tokens=2096,
|
65 |
+
temperature=0.5,
|
66 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
67 |
+
custom_role_conversions=None,
|
68 |
)
|
69 |
|
|
|
|
|
70 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
71 |
|
72 |
with open("prompts.yaml", 'r') as stream:
|
|
|
74 |
|
75 |
agent = CodeAgent(
|
76 |
model=model,
|
77 |
+
tools=[simulate_ai_debate, get_current_time_in_timezone, final_answer],
|
78 |
max_steps=6,
|
79 |
verbosity_level=1,
|
80 |
grammar=None,
|
|
|
84 |
prompt_templates=prompt_templates
|
85 |
)
|
86 |
|
87 |
+
GradioUI(agent).launch()
|
|