Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,7 @@
|
|
| 1 |
-
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
|
|
|
|
|
|
|
|
|
| 2 |
import datetime
|
| 3 |
import requests
|
| 4 |
import pytz
|
|
@@ -34,6 +37,52 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 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:
|
|
|
|
| 1 |
+
# from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
+
# 변경 후 (로컬 실행용)
|
| 3 |
+
from smolagents import CodeAgent, TransformersModel, load_tool, tool
|
| 4 |
+
|
| 5 |
import datetime
|
| 6 |
import requests
|
| 7 |
import pytz
|
|
|
|
| 37 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 38 |
|
| 39 |
|
| 40 |
+
final_answer = FinalAnswerTool()
|
| 41 |
+
|
| 42 |
+
# 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:
|
| 43 |
+
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 44 |
+
|
| 45 |
+
# model = HfApiModel(
|
| 46 |
+
# max_tokens=2096,
|
| 47 |
+
# temperature=0.5,
|
| 48 |
+
# model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
|
| 49 |
+
# custom_role_conversions=None,
|
| 50 |
+
# )
|
| 51 |
+
|
| 52 |
+
model = TransformersModel(
|
| 53 |
+
model_id="bigscience/bloomz-1b1",
|
| 54 |
+
device_map="auto", # Colab GPU 자동 할당
|
| 55 |
+
torch_dtype="auto", # 메모리 절약
|
| 56 |
+
max_new_tokens=512, # (= max_tokens 별칭으로도 동작)
|
| 57 |
+
temperature=0.7,
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
# Import tool from Hub
|
| 62 |
+
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 63 |
+
|
| 64 |
+
with open("prompts.yaml", 'r') as stream:
|
| 65 |
+
prompt_templates = yaml.safe_load(stream)
|
| 66 |
+
|
| 67 |
+
agent = CodeAgent(
|
| 68 |
+
model=model,
|
| 69 |
+
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 70 |
+
max_steps=6,
|
| 71 |
+
verbosity_level=1,
|
| 72 |
+
# grammar=None,
|
| 73 |
+
planning_interval=None,
|
| 74 |
+
name=None,
|
| 75 |
+
description=None,
|
| 76 |
+
prompt_templates=prompt_templates
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
GradioUI(agent).launch()
|
| 81 |
+
return f"The current local time in {timezone} is: {local_time}"
|
| 82 |
+
except Exception as e:
|
| 83 |
+
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 84 |
+
|
| 85 |
+
|
| 86 |
final_answer = FinalAnswerTool()
|
| 87 |
|
| 88 |
# 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:
|