Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
-
import
|
| 2 |
-
from smolagents import CodeAgent, HfApiModel, load_tool, tool
|
| 3 |
import datetime
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
-
from
|
| 8 |
|
| 9 |
# Below is an example of a tool that does nothing. Amaze us with your creativity!
|
| 10 |
@tool
|
|
@@ -23,21 +23,24 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 23 |
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
| 24 |
"""
|
| 25 |
try:
|
|
|
|
| 26 |
tz = pytz.timezone(timezone)
|
|
|
|
| 27 |
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 28 |
return f"The current local time in {timezone} is: {local_time}"
|
| 29 |
except Exception as e:
|
| 30 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 31 |
|
| 32 |
|
| 33 |
-
# Initialize FinalAnswerTool
|
| 34 |
final_answer = FinalAnswerTool()
|
| 35 |
|
| 36 |
-
#
|
|
|
|
|
|
|
| 37 |
model = HfApiModel(
|
| 38 |
max_tokens=2096,
|
| 39 |
temperature=0.5,
|
| 40 |
-
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
| 41 |
custom_role_conversions=None,
|
| 42 |
)
|
| 43 |
|
|
@@ -48,16 +51,18 @@ image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_co
|
|
| 48 |
with open("prompts.yaml", 'r') as stream:
|
| 49 |
prompt_templates = yaml.safe_load(stream)
|
| 50 |
|
| 51 |
-
#
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
| 61 |
|
| 62 |
-
#
|
| 63 |
-
|
|
|
|
| 1 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
|
|
|
|
| 2 |
import datetime
|
| 3 |
+
import requests
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
from Gradio_UI import GradioUI
|
| 8 |
|
| 9 |
# Below is an example of a tool that does nothing. Amaze us with your creativity!
|
| 10 |
@tool
|
|
|
|
| 23 |
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
| 24 |
"""
|
| 25 |
try:
|
| 26 |
+
# Create timezone object
|
| 27 |
tz = pytz.timezone(timezone)
|
| 28 |
+
# Get current time in that timezone
|
| 29 |
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 30 |
return f"The current local time in {timezone} is: {local_time}"
|
| 31 |
except Exception as e:
|
| 32 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 33 |
|
| 34 |
|
|
|
|
| 35 |
final_answer = FinalAnswerTool()
|
| 36 |
|
| 37 |
+
# 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:
|
| 38 |
+
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 39 |
+
|
| 40 |
model = HfApiModel(
|
| 41 |
max_tokens=2096,
|
| 42 |
temperature=0.5,
|
| 43 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct', # it is possible that this model may be overloaded
|
| 44 |
custom_role_conversions=None,
|
| 45 |
)
|
| 46 |
|
|
|
|
| 51 |
with open("prompts.yaml", 'r') as stream:
|
| 52 |
prompt_templates = yaml.safe_load(stream)
|
| 53 |
|
| 54 |
+
# Initialize the agent with tools
|
| 55 |
+
agent = CodeAgent(
|
| 56 |
+
model=model,
|
| 57 |
+
tools=[final_answer, get_current_time_in_timezone, my_custom_tool, image_generation_tool], # add your tools here (don't remove final answer)
|
| 58 |
+
max_steps=6,
|
| 59 |
+
verbosity_level=1,
|
| 60 |
+
grammar=None,
|
| 61 |
+
planning_interval=None,
|
| 62 |
+
name=None,
|
| 63 |
+
description=None,
|
| 64 |
+
prompt_templates=prompt_templates
|
| 65 |
+
)
|
| 66 |
|
| 67 |
+
# Launch Gradio UI
|
| 68 |
+
GradioUI(agent).launch()
|