Hasan Malik commited on
Commit
676d158
·
unverified ·
2 Parent(s): 697271cf4e4dc1

Merge pull request #2 from hasanmalik825-gh/dev

Browse files
Files changed (2) hide show
  1. app.py +7 -4
  2. test.ipynb +0 -295
app.py CHANGED
@@ -8,14 +8,16 @@ from tools.final_answer import FinalAnswerTool
8
  from Gradio_UI import GradioUI
9
  from typing import Dict, Any
10
 
11
-
12
  @tool
13
- def get_stock_info(symbol: str)-> Dict[str, Any]:
14
  """
15
- A tool that gets current stock information for a given symbol.
16
 
17
  Args:
18
- symbol (str): Stock symbol (e.g., 'AAPL' for Apple)
 
 
 
19
  """
20
  try:
21
  # Create ticker object
@@ -37,6 +39,7 @@ def get_stock_info(symbol: str)-> Dict[str, Any]:
37
  }
38
  except Exception as e:
39
  print(f"Error fetching data for {symbol}: {str(e)}")
 
40
 
41
  @tool
42
  def get_current_time_in_timezone(timezone: str) -> str:
 
8
  from Gradio_UI import GradioUI
9
  from typing import Dict, Any
10
 
 
11
  @tool
12
+ def get_stock_info(symbol: str) -> Dict[str, Any]:
13
  """
14
+ A tool that fetches current stock information for a given symbol.
15
 
16
  Args:
17
+ symbol (str): The stock symbol for which to retrieve information (e.g., 'AAPL' for Apple, 'GOOG' for Google).
18
+
19
+ Returns:
20
+ Dict[str, Any]: A dictionary containing stock information, such as current price, today's high/low, and market cap.
21
  """
22
  try:
23
  # Create ticker object
 
39
  }
40
  except Exception as e:
41
  print(f"Error fetching data for {symbol}: {str(e)}")
42
+ return {"Error": str(e)} # Return the error in a friendly format
43
 
44
  @tool
45
  def get_current_time_in_timezone(timezone: str) -> str:
test.ipynb DELETED
@@ -1,295 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "code",
5
- "execution_count": 10,
6
- "metadata": {},
7
- "outputs": [
8
- {
9
- "name": "stdout",
10
- "output_type": "stream",
11
- "text": [
12
- "Collecting yfinance\n",
13
- " Downloading yfinance-0.2.53-py2.py3-none-any.whl.metadata (5.8 kB)\n",
14
- "Requirement already satisfied: pandas>=1.3.0 in c:\\users\\homepc\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from yfinance) (2.2.3)\n",
15
- "Requirement already satisfied: numpy>=1.16.5 in c:\\users\\homepc\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from yfinance) (1.26.4)\n",
16
- "Requirement already satisfied: requests>=2.31 in c:\\users\\homepc\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from yfinance) (2.32.3)\n",
17
- "Collecting multitasking>=0.0.7 (from yfinance)\n",
18
- " Downloading multitasking-0.0.11-py3-none-any.whl.metadata (5.5 kB)\n",
19
- "Requirement already satisfied: platformdirs>=2.0.0 in c:\\users\\homepc\\appdata\\roaming\\python\\python311\\site-packages (from yfinance) (4.3.6)\n",
20
- "Requirement already satisfied: pytz>=2022.5 in c:\\users\\homepc\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from yfinance) (2024.2)\n",
21
- "Collecting frozendict>=2.3.4 (from yfinance)\n",
22
- " Downloading frozendict-2.4.6-py311-none-any.whl.metadata (23 kB)\n",
23
- "Collecting peewee>=3.16.2 (from yfinance)\n",
24
- " Downloading peewee-3.17.9.tar.gz (3.0 MB)\n",
25
- " ---------------------------------------- 0.0/3.0 MB ? eta -:--:--\n",
26
- " ---------------------------------------- 0.0/3.0 MB ? eta -:--:--\n",
27
- " --- ------------------------------------ 0.3/3.0 MB ? eta -:--:--\n",
28
- " ------ --------------------------------- 0.5/3.0 MB 670.4 kB/s eta 0:00:04\n",
29
- " ------ --------------------------------- 0.5/3.0 MB 670.4 kB/s eta 0:00:04\n",
30
- " ---------- ----------------------------- 0.8/3.0 MB 729.2 kB/s eta 0:00:04\n",
31
- " ---------- ----------------------------- 0.8/3.0 MB 729.2 kB/s eta 0:00:04\n",
32
- " ------------- -------------------------- 1.0/3.0 MB 739.8 kB/s eta 0:00:03\n",
33
- " ----------------- ---------------------- 1.3/3.0 MB 808.5 kB/s eta 0:00:03\n",
34
- " ------------------------ --------------- 1.8/3.0 MB 977.5 kB/s eta 0:00:02\n",
35
- " --------------------------- ------------ 2.1/3.0 MB 978.7 kB/s eta 0:00:01\n",
36
- " --------------------------- ------------ 2.1/3.0 MB 978.7 kB/s eta 0:00:01\n",
37
- " ------------------------------- -------- 2.4/3.0 MB 958.5 kB/s eta 0:00:01\n",
38
- " ------------------------------- -------- 2.4/3.0 MB 958.5 kB/s eta 0:00:01\n",
39
- " ---------------------------------- ----- 2.6/3.0 MB 883.0 kB/s eta 0:00:01\n",
40
- " ---------------------------------- ----- 2.6/3.0 MB 883.0 kB/s eta 0:00:01\n",
41
- " -------------------------------------- - 2.9/3.0 MB 822.3 kB/s eta 0:00:01\n",
42
- " ---------------------------------------- 3.0/3.0 MB 815.1 kB/s eta 0:00:00\n",
43
- " Installing build dependencies: started\n",
44
- " Installing build dependencies: finished with status 'done'\n",
45
- " Getting requirements to build wheel: started\n",
46
- " Getting requirements to build wheel: finished with status 'done'\n",
47
- " Preparing metadata (pyproject.toml): started\n",
48
- " Preparing metadata (pyproject.toml): finished with status 'done'\n",
49
- "Requirement already satisfied: beautifulsoup4>=4.11.1 in c:\\users\\homepc\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from yfinance) (4.12.3)\n",
50
- "Requirement already satisfied: soupsieve>1.2 in c:\\users\\homepc\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from beautifulsoup4>=4.11.1->yfinance) (2.6)\n",
51
- "Requirement already satisfied: python-dateutil>=2.8.2 in c:\\users\\homepc\\appdata\\roaming\\python\\python311\\site-packages (from pandas>=1.3.0->yfinance) (2.9.0.post0)\n",
52
- "Requirement already satisfied: tzdata>=2022.7 in c:\\users\\homepc\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from pandas>=1.3.0->yfinance) (2024.2)\n",
53
- "Requirement already satisfied: charset-normalizer<4,>=2 in c:\\users\\homepc\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from requests>=2.31->yfinance) (3.4.0)\n",
54
- "Requirement already satisfied: idna<4,>=2.5 in c:\\users\\homepc\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from requests>=2.31->yfinance) (3.10)\n",
55
- "Requirement already satisfied: urllib3<3,>=1.21.1 in c:\\users\\homepc\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from requests>=2.31->yfinance) (2.2.3)\n",
56
- "Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\homepc\\appdata\\local\\programs\\python\\python311\\lib\\site-packages (from requests>=2.31->yfinance) (2024.8.30)\n",
57
- "Requirement already satisfied: six>=1.5 in c:\\users\\homepc\\appdata\\roaming\\python\\python311\\site-packages (from python-dateutil>=2.8.2->pandas>=1.3.0->yfinance) (1.16.0)\n",
58
- "Downloading yfinance-0.2.53-py2.py3-none-any.whl (108 kB)\n",
59
- "Downloading frozendict-2.4.6-py311-none-any.whl (16 kB)\n",
60
- "Downloading multitasking-0.0.11-py3-none-any.whl (8.5 kB)\n",
61
- "Building wheels for collected packages: peewee\n",
62
- " Building wheel for peewee (pyproject.toml): started\n",
63
- " Building wheel for peewee (pyproject.toml): finished with status 'done'\n",
64
- " Created wheel for peewee: filename=peewee-3.17.9-py3-none-any.whl size=139096 sha256=29a4719e5b3df9682254f061dc1a51196a8b298f14f6452d51d027969ae8bb41\n",
65
- " Stored in directory: c:\\users\\homepc\\appdata\\local\\pip\\cache\\wheels\\f4\\14\\e4\\50c88c865833085aeb91e2bd40e3a683ff434806386b8ee7bc\n",
66
- "Successfully built peewee\n",
67
- "Installing collected packages: peewee, multitasking, frozendict, yfinance\n",
68
- "Successfully installed frozendict-2.4.6 multitasking-0.0.11 peewee-3.17.9 yfinance-0.2.53\n",
69
- "Note: you may need to restart the kernel to use updated packages.\n"
70
- ]
71
- }
72
- ],
73
- "source": [
74
- "!pip install yfinance"
75
- ]
76
- },
77
- {
78
- "cell_type": "code",
79
- "execution_count": 28,
80
- "metadata": {},
81
- "outputs": [],
82
- "source": [
83
- "import yfinance as yf\n",
84
- "from datetime import datetime\n",
85
- "\n",
86
- "def get_stock_info(symbol: str)-> dict:\n",
87
- " \"\"\"\n",
88
- " A tool that gets current stock information for a given symbol.\n",
89
- " \n",
90
- " Args:\n",
91
- " symbol (str): Stock symbol (e.g., 'AAPL' for Apple)\n",
92
- " \"\"\"\n",
93
- " try:\n",
94
- " # Create ticker object\n",
95
- " ticker = yf.Ticker(symbol)\n",
96
- " # Get current stock info\n",
97
- " info = ticker.info\n",
98
- " current_price = info.get('currentPrice', 'NA')\n",
99
- " market_cap = info.get('marketCap', 'NA') \n",
100
- " # Get today's data\n",
101
- " today_data = ticker.history(period='1d')\n",
102
- " \n",
103
- " return {\n",
104
- " \"Stock\": symbol.upper(),\n",
105
- " \"Current Price\": current_price,\n",
106
- " \"Today's High\": today_data['High'].iloc[0] or \"NA\",\n",
107
- " \"Today's Low\": today_data['Low'].iloc[0] or \"NA\",\n",
108
- " \"Volume\": today_data['Volume'].iloc[0] or \"NA\",\n",
109
- " \"MarketCap\": market_cap\n",
110
- " }\n",
111
- " except Exception as e:\n",
112
- " print(f\"Error fetching data for {symbol}: {str(e)}\")"
113
- ]
114
- },
115
- {
116
- "cell_type": "code",
117
- "execution_count": 29,
118
- "metadata": {},
119
- "outputs": [
120
- {
121
- "data": {
122
- "text/plain": [
123
- "{'Stock': 'ETH',\n",
124
- " 'Current Price': 'NA',\n",
125
- " \"Today's High\": 26.31999969482422,\n",
126
- " \"Today's Low\": 25.365999221801758,\n",
127
- " 'Volume': 1148800,\n",
128
- " 'MarketCap': 'NA'}"
129
- ]
130
- },
131
- "execution_count": 29,
132
- "metadata": {},
133
- "output_type": "execute_result"
134
- }
135
- ],
136
- "source": [
137
- "get_stock_info('eth')"
138
- ]
139
- },
140
- {
141
- "cell_type": "code",
142
- "execution_count": null,
143
- "metadata": {},
144
- "outputs": [],
145
- "source": []
146
- },
147
- {
148
- "cell_type": "code",
149
- "execution_count": 12,
150
- "metadata": {},
151
- "outputs": [
152
- {
153
- "name": "stdout",
154
- "output_type": "stream",
155
- "text": [
156
- "Stock Market Information\n",
157
- "========================================\n",
158
- "\n",
159
- "Stock Information for AAPL\n",
160
- "========================================\n",
161
- "Current Price: $244.6\n",
162
- "Previous Close: $241.53\n",
163
- "Day's High: $245.55\n",
164
- "Day's Low: $240.99\n",
165
- "Volume: 40,838,100\n",
166
- "Market Cap: $3674.41B\n",
167
- "\n",
168
- "Last Updated: 2025-02-17 21:46:59\n",
169
- "\n"
170
- ]
171
- },
172
- {
173
- "name": "stderr",
174
- "output_type": "stream",
175
- "text": [
176
- "C:\\Users\\HomePC\\AppData\\Local\\Temp\\ipykernel_22112\\1949323000.py:30: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`\n",
177
- " print(f\"Day's High: ${today_data['High'][0]:.2f}\")\n",
178
- "C:\\Users\\HomePC\\AppData\\Local\\Temp\\ipykernel_22112\\1949323000.py:31: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`\n",
179
- " print(f\"Day's Low: ${today_data['Low'][0]:.2f}\")\n",
180
- "C:\\Users\\HomePC\\AppData\\Local\\Temp\\ipykernel_22112\\1949323000.py:32: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`\n",
181
- " print(f\"Volume: {today_data['Volume'][0]:,.0f}\")\n"
182
- ]
183
- },
184
- {
185
- "name": "stdout",
186
- "output_type": "stream",
187
- "text": [
188
- "\n",
189
- "Stock Information for MSFT\n",
190
- "========================================\n",
191
- "Current Price: $408.43\n",
192
- "Previous Close: $410.54\n",
193
- "Day's High: $408.91\n",
194
- "Day's Low: $405.88\n",
195
- "Volume: 22,680,000\n",
196
- "Market Cap: $3036.26B\n",
197
- "\n",
198
- "Last Updated: 2025-02-17 21:47:00\n",
199
- "\n"
200
- ]
201
- },
202
- {
203
- "name": "stderr",
204
- "output_type": "stream",
205
- "text": [
206
- "C:\\Users\\HomePC\\AppData\\Local\\Temp\\ipykernel_22112\\1949323000.py:30: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`\n",
207
- " print(f\"Day's High: ${today_data['High'][0]:.2f}\")\n",
208
- "C:\\Users\\HomePC\\AppData\\Local\\Temp\\ipykernel_22112\\1949323000.py:31: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`\n",
209
- " print(f\"Day's Low: ${today_data['Low'][0]:.2f}\")\n",
210
- "C:\\Users\\HomePC\\AppData\\Local\\Temp\\ipykernel_22112\\1949323000.py:32: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`\n",
211
- " print(f\"Volume: {today_data['Volume'][0]:,.0f}\")\n"
212
- ]
213
- },
214
- {
215
- "name": "stdout",
216
- "output_type": "stream",
217
- "text": [
218
- "\n",
219
- "Stock Information for GOOGL\n",
220
- "========================================\n",
221
- "Current Price: $185.23\n",
222
- "Previous Close: $186.14\n",
223
- "Day's High: $186.40\n",
224
- "Day's Low: $184.32\n",
225
- "Volume: 20,402,300\n",
226
- "Market Cap: $2266.97B\n",
227
- "\n",
228
- "Last Updated: 2025-02-17 21:47:01\n",
229
- "\n",
230
- "Have a nice day! :)\n"
231
- ]
232
- },
233
- {
234
- "name": "stderr",
235
- "output_type": "stream",
236
- "text": [
237
- "C:\\Users\\HomePC\\AppData\\Local\\Temp\\ipykernel_22112\\1949323000.py:30: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`\n",
238
- " print(f\"Day's High: ${today_data['High'][0]:.2f}\")\n",
239
- "C:\\Users\\HomePC\\AppData\\Local\\Temp\\ipykernel_22112\\1949323000.py:31: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`\n",
240
- " print(f\"Day's Low: ${today_data['Low'][0]:.2f}\")\n",
241
- "C:\\Users\\HomePC\\AppData\\Local\\Temp\\ipykernel_22112\\1949323000.py:32: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`\n",
242
- " print(f\"Volume: {today_data['Volume'][0]:,.0f}\")\n"
243
- ]
244
- }
245
- ],
246
- "source": [
247
- "symbols = ['AAPL', 'MSFT', 'GOOGL']\n",
248
- "\n",
249
- "print(\"Stock Market Information\")\n",
250
- "print(\"=\" * 40)\n",
251
- "\n",
252
- "for symbol in symbols:\n",
253
- " get_stock_info(symbol)\n",
254
- " print()\n",
255
- "\n",
256
- "print(\"Have a nice day! :)\")"
257
- ]
258
- },
259
- {
260
- "cell_type": "code",
261
- "execution_count": null,
262
- "metadata": {},
263
- "outputs": [],
264
- "source": []
265
- },
266
- {
267
- "cell_type": "code",
268
- "execution_count": null,
269
- "metadata": {},
270
- "outputs": [],
271
- "source": []
272
- }
273
- ],
274
- "metadata": {
275
- "kernelspec": {
276
- "display_name": "Python 3",
277
- "language": "python",
278
- "name": "python3"
279
- },
280
- "language_info": {
281
- "codemirror_mode": {
282
- "name": "ipython",
283
- "version": 3
284
- },
285
- "file_extension": ".py",
286
- "mimetype": "text/x-python",
287
- "name": "python",
288
- "nbconvert_exporter": "python",
289
- "pygments_lexer": "ipython3",
290
- "version": "3.11.0"
291
- }
292
- },
293
- "nbformat": 4,
294
- "nbformat_minor": 2
295
- }