Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import datetime
|
| 2 |
+
import pytz
|
| 3 |
+
import os
|
| 4 |
+
from smolagents import CodeAgent, InferenceClientModel, tool, GradioUI
|
| 5 |
+
|
| 6 |
+
# --- ツール定義 ---
|
| 7 |
+
@tool
|
| 8 |
+
def get_current_time_in_timezone(timezone: str) -> str:
|
| 9 |
+
"""A tool that fetches the current local time in a specified timezone.
|
| 10 |
+
Args:
|
| 11 |
+
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
| 12 |
+
"""
|
| 13 |
+
try:
|
| 14 |
+
tz = pytz.timezone(timezone)
|
| 15 |
+
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 16 |
+
return f"The current local time in {timezone} is: {local_time}"
|
| 17 |
+
except Exception as e:
|
| 18 |
+
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 19 |
+
|
| 20 |
+
# --- モデル設定 ---
|
| 21 |
+
# Space上ではHF_TOKENが自動で読み込まれます
|
| 22 |
+
model = InferenceClientModel(
|
| 23 |
+
model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 24 |
+
token=os.environ.get("HF_TOKEN")
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
# --- エージェント作成 ---
|
| 28 |
+
agent = CodeAgent(
|
| 29 |
+
tools=[get_current_time_in_timezone],
|
| 30 |
+
model=model,
|
| 31 |
+
add_base_tools=True
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
# --- UI起動 ---
|
| 35 |
+
GradioUI(agent).launch()
|