ajitkumar22 commited on
Commit
f679fa0
·
verified ·
1 Parent(s): 321f9ea

Update app.py

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