shhuangmust commited on
Commit
8106d6f
·
verified ·
1 Parent(s): 676b0d0

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -77
app.py DELETED
@@ -1,77 +0,0 @@
1
- # === SmolAgents範例 ===
2
- # 這個範例展示了如何使用 SmolAgents 來創建一個簡單的應用程式,該應用程式可以生成圖像並回答問題。
3
- # 這個範例使用了 Hugging Face 的 Qwen2.5-Coder-32B-Instruct 模型來生成圖像和回答問題。
4
- # 這個範例使用了 Gradio 來創建一個簡單的用戶界面,允許用戶輸入問題並獲得回答。
5
- # 這個範例使用了 DuckDuckGoSearchTool 來搜索問題的答案。
6
- # 這個範例使用了 pytz 來獲取當前的本地時間。
7
- # SmolAgents官方文件:https://huggingface.co/docs/smolagents/v1.14.0/en/reference/models
8
-
9
- from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel,load_tool,tool
10
- import datetime
11
- import requests
12
- import pytz
13
- import yaml
14
- from tools.final_answer import FinalAnswerTool
15
-
16
- from Gradio_UI import GradioUI
17
-
18
- # Below is an example of a tool that does nothing. Amaze us with your creativity !
19
- @tool
20
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
21
- #Keep this format for the description / args / args description but feel free to modify the tool
22
- """A tool that does nothing yet
23
- Args:
24
- arg1: the first argument
25
- arg2: the second argument
26
- """
27
- return "What magic will you build ?"
28
-
29
- @tool
30
- def get_current_time_in_timezone(timezone: str) -> str:
31
- """A tool that fetches the current local time in a specified timezone.
32
- Args:
33
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
34
- """
35
- try:
36
- # Create timezone object
37
- tz = pytz.timezone(timezone)
38
- # Get current time in that timezone
39
- local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
40
- return f"The current local time in {timezone} is: {local_time}"
41
- except Exception as e:
42
- return f"Error fetching time for timezone '{timezone}': {str(e)}"
43
-
44
-
45
- final_answer = FinalAnswerTool()
46
-
47
- # 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:
48
- # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
49
-
50
- model = HfApiModel(
51
- max_tokens=2096,
52
- temperature=0.5,
53
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
54
- custom_role_conversions=None,
55
- )
56
-
57
-
58
- # Import tool from Hub
59
- image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
60
-
61
- with open("prompts.yaml", 'r') as stream:
62
- prompt_templates = yaml.safe_load(stream)
63
-
64
- agent = CodeAgent(
65
- model=model,
66
- tools=[final_answer], ## add your tools here (don't remove final answer)
67
- max_steps=6,
68
- verbosity_level=1,
69
- grammar=None,
70
- planning_interval=None,
71
- name=None,
72
- description=None,
73
- prompt_templates=prompt_templates
74
- )
75
-
76
-
77
- GradioUI(agent).launch()