Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,127 +8,119 @@ import random
|
|
8 |
|
9 |
from Gradio_UI import GradioUI
|
10 |
|
11 |
-
import os
|
12 |
-
from huggingface_hub import InferenceClient
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
client = InferenceClient(token=HF_API_KEY)
|
19 |
-
|
20 |
-
response = client.text_generation("Hello!", model="Qwen/Qwen2.5-Coder-32B-Instruct")
|
21 |
-
print(response)
|
22 |
-
|
23 |
-
# @tool
|
24 |
-
# def futuristic_profession_predictor(name: str) -> str:
|
25 |
-
# """Predicts the person's profession in the year 2050 based on their name.
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
#
|
46 |
-
|
47 |
-
|
48 |
-
#
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
#
|
67 |
-
|
68 |
-
|
69 |
-
#
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
#
|
87 |
-
|
88 |
-
#
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
#
|
98 |
-
#
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
#
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
|
114 |
-
|
115 |
-
|
116 |
-
#
|
117 |
-
|
118 |
-
|
119 |
-
#
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
|
|
|
|
|
|
126 |
|
127 |
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel
|
128 |
|
129 |
-
|
130 |
|
131 |
#agent.run("Search for the best music recommendations for a party at the Wayne's mansion.")
|
132 |
|
133 |
|
134 |
-
GradioUI(
|
|
|
8 |
|
9 |
from Gradio_UI import GradioUI
|
10 |
|
|
|
|
|
11 |
|
12 |
+
@tool
|
13 |
+
def futuristic_profession_predictor(name: str) -> str:
|
14 |
+
"""Predicts the person's profession in the year 2050 based on their name.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
Args:
|
17 |
+
name: The name of the person.
|
18 |
+
"""
|
19 |
+
professions = [
|
20 |
+
"Quantum Data Alchemist",
|
21 |
+
"Neural Interface Designer",
|
22 |
+
"AI-Powered Philosopher",
|
23 |
+
"Martian Agriculture Specialist",
|
24 |
+
"Virtual Reality Psychologist",
|
25 |
+
"Holographic Content Creator",
|
26 |
+
"Synthetic Biology Engineer",
|
27 |
+
"Time Travel Consultant",
|
28 |
+
"Cybersecurity Shaman"
|
29 |
+
]
|
30 |
|
31 |
+
prediction = random.choice(professions)
|
32 |
+
return f"In the year 2050, {name} will be a {prediction}!"
|
33 |
+
|
34 |
+
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
35 |
+
@tool
|
36 |
+
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
37 |
+
#Keep this format for the description / args / args description but feel free to modify the tool
|
38 |
+
"""A tool that does nothing yet
|
39 |
+
Args:
|
40 |
+
arg1: the first argument
|
41 |
+
arg2: the second argument
|
42 |
+
"""
|
43 |
+
return "What magic will you build ?"
|
44 |
+
|
45 |
+
|
46 |
+
@tool
|
47 |
+
def findLoveOfTwoNumbers(arg1:int, arg2:int)-> int:
|
48 |
+
""" A tool that returns Love of two numbers
|
49 |
+
Args:
|
50 |
+
arg1: the first argument
|
51 |
+
arg2: the second argument
|
52 |
+
"""
|
53 |
+
return arg1+arg2 - 20
|
54 |
+
|
55 |
+
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
56 |
+
@tool
|
57 |
+
def personIdentifier(arg1:str)-> int: #it's important to specify the return type
|
58 |
+
#Keep this format for the description / args / args description but feel free to modify the tool
|
59 |
+
"""A Tool that identifies the person. For example,
|
60 |
+
Task: Who is Ajit Kumar?
|
61 |
+
Answer: He is a professor at Shiv Nadar University.
|
62 |
|
63 |
+
Args:
|
64 |
+
arg1: the first argument
|
65 |
+
"""
|
66 |
+
return "He is a professor at Shiv Nadar University"
|
67 |
+
|
68 |
+
@tool
|
69 |
+
def get_current_time_in_timezone(timezone: str) -> str:
|
70 |
+
"""A tool that fetches the current local time in a specified timezone.
|
71 |
+
Args:
|
72 |
+
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
73 |
+
"""
|
74 |
+
try:
|
75 |
+
# Create timezone object
|
76 |
+
tz = pytz.timezone(timezone)
|
77 |
+
# Get current time in that timezone
|
78 |
+
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
79 |
+
return f"The current local time in {timezone} is: {local_time}"
|
80 |
+
except Exception as e:
|
81 |
+
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
82 |
+
|
83 |
+
|
84 |
+
final_answer = FinalAnswerTool()
|
85 |
+
|
86 |
+
# 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:
|
87 |
+
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
88 |
+
|
89 |
+
model = HfApiModel(
|
90 |
+
max_tokens=2096,
|
91 |
+
temperature=0.5,
|
92 |
+
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
|
93 |
+
custom_role_conversions=None,
|
94 |
+
)
|
95 |
+
|
96 |
+
|
97 |
+
# Import tool from Hub
|
98 |
+
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
99 |
+
|
100 |
+
with open("prompts.yaml", 'r') as stream:
|
101 |
+
prompt_templates = yaml.safe_load(stream)
|
102 |
|
103 |
+
agent = CodeAgent(
|
104 |
+
model=model,
|
105 |
+
#tools=[final_answer, image_generation_tool, DuckDuckGoSearchTool()], ## add your tools here (don't remove final answer)
|
106 |
+
tools = [
|
107 |
+
DuckDuckGoSearchTool(),
|
108 |
+
#final_answer, futuristic_profession_predictor, personIdentifier, findLoveOfTwoNumbers
|
109 |
+
],
|
110 |
+
max_steps=20,
|
111 |
+
verbosity_level=1,
|
112 |
+
grammar=None,
|
113 |
+
planning_interval=None,
|
114 |
+
name=None,
|
115 |
+
description=None,
|
116 |
+
prompt_templates=prompt_templates
|
117 |
+
)
|
118 |
|
119 |
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel
|
120 |
|
121 |
+
#agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=HfApiModel())
|
122 |
|
123 |
#agent.run("Search for the best music recommendations for a party at the Wayne's mansion.")
|
124 |
|
125 |
|
126 |
+
GradioUI(agent).launch()
|