Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,54 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
import yaml
|
|
|
|
|
|
|
| 3 |
from tools.final_answer import FinalAnswerTool
|
| 4 |
from Gradio_UI import GradioUI
|
| 5 |
-
from tool import my_custom_tool, get_current_time_in_timezone
|
| 6 |
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
#
|
|
|
|
|
|
|
| 10 |
with open("simple_prompts.yaml") as f:
|
| 11 |
prompt_templates = yaml.safe_load(f)
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
|
|
|
|
| 15 |
model = HfApiModel(
|
| 16 |
-
max_tokens=2096,
|
| 17 |
-
temperature=0.5,
|
| 18 |
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
|
|
|
|
|
|
| 19 |
)
|
| 20 |
|
| 21 |
-
|
|
|
|
| 22 |
agent = CodeAgent(
|
| 23 |
model=model,
|
| 24 |
tools=[final_answer, my_custom_tool, get_current_time_in_timezone],
|
|
@@ -27,4 +57,7 @@ agent = CodeAgent(
|
|
| 27 |
verbosity_level=1,
|
| 28 |
)
|
| 29 |
|
|
|
|
|
|
|
|
|
|
| 30 |
GradioUI(agent).launch()
|
|
|
|
| 1 |
+
import datetime
|
| 2 |
+
import pytz
|
| 3 |
import yaml
|
| 4 |
+
from smolagents import CodeAgent, HfApiModel
|
| 5 |
+
from smolagents.tools import tool
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
from Gradio_UI import GradioUI
|
|
|
|
| 8 |
|
| 9 |
+
# -----------------------------
|
| 10 |
+
# ✅ Define tools directly here
|
| 11 |
+
# -----------------------------
|
| 12 |
+
|
| 13 |
+
@tool
|
| 14 |
+
def my_custom_tool(arg1: str, arg2: int) -> str:
|
| 15 |
+
"""A tool that does nothing yet
|
| 16 |
+
Args:
|
| 17 |
+
arg1: the first argument
|
| 18 |
+
arg2: the second argument
|
| 19 |
+
"""
|
| 20 |
+
return "What magic will you build?"
|
| 21 |
+
|
| 22 |
+
@tool
|
| 23 |
+
def get_current_time_in_timezone(timezone: str) -> str:
|
| 24 |
+
"""Fetch the current local time in a specified timezone.
|
| 25 |
+
Args:
|
| 26 |
+
timezone: A valid timezone string (e.g., 'America/New_York').
|
| 27 |
+
"""
|
| 28 |
+
try:
|
| 29 |
+
tz = pytz.timezone(timezone)
|
| 30 |
+
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 31 |
+
return f"The current local time in {timezone} is: {local_time}"
|
| 32 |
+
except Exception as e:
|
| 33 |
+
return f"Error: {str(e)}"
|
| 34 |
|
| 35 |
+
# -----------------------------
|
| 36 |
+
# ✅ Load simplified prompt template
|
| 37 |
+
# -----------------------------
|
| 38 |
with open("simple_prompts.yaml") as f:
|
| 39 |
prompt_templates = yaml.safe_load(f)
|
| 40 |
|
| 41 |
+
# -----------------------------
|
| 42 |
+
# ✅ Set up model and agent
|
| 43 |
+
# -----------------------------
|
| 44 |
model = HfApiModel(
|
|
|
|
|
|
|
| 45 |
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
| 46 |
+
max_tokens=2048,
|
| 47 |
+
temperature=0.5
|
| 48 |
)
|
| 49 |
|
| 50 |
+
final_answer = FinalAnswerTool()
|
| 51 |
+
|
| 52 |
agent = CodeAgent(
|
| 53 |
model=model,
|
| 54 |
tools=[final_answer, my_custom_tool, get_current_time_in_timezone],
|
|
|
|
| 57 |
verbosity_level=1,
|
| 58 |
)
|
| 59 |
|
| 60 |
+
# -----------------------------
|
| 61 |
+
# ✅ Launch Gradio interface
|
| 62 |
+
# -----------------------------
|
| 63 |
GradioUI(agent).launch()
|