Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,58 +1,25 @@
|
|
| 1 |
-
from smolagents import CodeAgent,
|
| 2 |
-
import datetime
|
| 3 |
-
import requests
|
| 4 |
-
import pytz
|
| 5 |
-
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
-
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
@tool
|
| 11 |
-
def
|
| 12 |
-
""
|
| 13 |
-
Args:
|
| 14 |
-
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
| 15 |
-
"""
|
| 16 |
-
try:
|
| 17 |
-
# Create timezone object
|
| 18 |
-
tz = pytz.timezone(timezone)
|
| 19 |
-
# Get current time in that timezone
|
| 20 |
-
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
| 21 |
-
return f"The current local time in {timezone} is: {local_time}"
|
| 22 |
-
except Exception as e:
|
| 23 |
-
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 24 |
-
|
| 25 |
|
| 26 |
final_answer = FinalAnswerTool()
|
| 27 |
|
| 28 |
-
# 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:
|
| 29 |
-
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 30 |
-
|
| 31 |
model = HfApiModel(
|
| 32 |
-
max_tokens=2096,
|
| 33 |
-
temperature=0.5,
|
| 34 |
-
model_id='
|
| 35 |
-
custom_role_conversions=None,
|
| 36 |
)
|
| 37 |
|
| 38 |
-
|
| 39 |
-
# Import tool from Hub
|
| 40 |
-
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 41 |
-
|
| 42 |
-
with open("prompts.yaml", 'r') as stream:
|
| 43 |
-
prompt_templates = yaml.safe_load(stream)
|
| 44 |
-
|
| 45 |
agent = CodeAgent(
|
| 46 |
model=model,
|
| 47 |
-
tools=[final_answer,
|
| 48 |
max_steps=6,
|
| 49 |
-
verbosity_level=
|
| 50 |
-
|
| 51 |
-
planning_interval=None,
|
| 52 |
-
name=None,
|
| 53 |
-
description=None,
|
| 54 |
-
prompt_templates=prompt_templates
|
| 55 |
)
|
| 56 |
|
| 57 |
-
|
| 58 |
GradioUI(agent).launch()
|
|
|
|
| 1 |
+
from smolagents import CodeAgent, HfApiModel, tool
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
| 3 |
from Gradio_UI import GradioUI
|
| 4 |
|
| 5 |
@tool
|
| 6 |
+
def say_hello(name: str) -> str:
|
| 7 |
+
return f"Hello, {name}!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
final_answer = FinalAnswerTool()
|
| 10 |
|
|
|
|
|
|
|
|
|
|
| 11 |
model = HfApiModel(
|
| 12 |
+
max_tokens=2096,
|
| 13 |
+
temperature=0.5,
|
| 14 |
+
model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud', # Альтернативный endpoint
|
|
|
|
| 15 |
)
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
agent = CodeAgent(
|
| 18 |
model=model,
|
| 19 |
+
tools=[final_answer, say_hello],
|
| 20 |
max_steps=6,
|
| 21 |
+
verbosity_level=2, # Больше логов
|
| 22 |
+
prompt_templates={"default": "Answer: {{question}}"},
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
)
|
| 24 |
|
|
|
|
| 25 |
GradioUI(agent).launch()
|