Spaces:
Runtime error
Runtime error
DylanonWic
commited on
Upload 11 files
Browse files- gplace.ipynb +7 -7
- tools.ipynb +71 -3
- tools.py +36 -3
gplace.ipynb
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
-
"execution_count":
|
6 |
"metadata": {},
|
7 |
"outputs": [],
|
8 |
"source": [
|
@@ -12,7 +12,7 @@
|
|
12 |
},
|
13 |
{
|
14 |
"cell_type": "code",
|
15 |
-
"execution_count":
|
16 |
"metadata": {},
|
17 |
"outputs": [],
|
18 |
"source": [
|
@@ -39,7 +39,7 @@
|
|
39 |
{
|
40 |
"data": {
|
41 |
"text/plain": [
|
42 |
-
"'1. Fashion Island\\nAddress: 587-589/7-9, Ram Inthra Rd, Khwaeng Khan Na Yao, Khet Khan Na Yao, Krung Thep Maha Nakhon 10230, Thailand\\nGoogle place ID: ChIJd57HEQRjHTERG_xSTcdQoYs\\nPhone: 02 947 5000\\nWebsite: http://www.fashionisland.co.th/\\n\\n\\n2. Food Island-Fashion Island\\nAddress: 5/5-6 หมู่ 5 Fashion Island, Ram Inthra Rd, Khwaeng Khan Na Yao, บางเขน Krung Thep Maha Nakhon 10220, Thailand\\nGoogle place ID: ChIJxVlvKA9jHTERAaDXThEk0sU\\nPhone: Unknown\\nWebsite: https://www.fashionisland.co.th/\\n\\n\\n3. Grand Station @ Fashion Island\\nAddress: Fashion Island Shopping Mall คันนายาว Khet Khan Na Yao, Krung Thep Maha Nakhon 10230, Thailand\\nGoogle place ID: ChIJgYJ0xNxjHTERqh7EMAXGflk\\nPhone: 02 947 5000\\nWebsite: https://www.fashionisland.co.th/about-us/grandstation/\\n\\n\\n4. Central Department Store Fashion Island\\nAddress: 591 Ram Inthra Rd, Khwaeng Khan Na Yao, Khet Khan Na Yao, Krung Thep Maha Nakhon 10230, Thailand\\nGoogle place ID: ChIJU51oO09jHTERkAkthlfrvMQ\\nPhone: 02 947 5320\\nWebsite: http://www.central.co.th/\\n\\n\\n5. Pomelo Fashion Island\\nAddress: Unit GSSH101, 1st Floor, Fashion Island Shopping Mall, 587-589, Ramindra Rd, แขวงคันนายาว เขตคันนายาว กรุงเทพมหานคร 10230, Thailand\\nGoogle place ID: ChIJaYz1YRFjHTERHcxGtqrypsk\\nPhone: 02 000 6811\\nWebsite: https://www.pomelofashion.com/\\n\\n\\n6. Fashion Island\\nAddress: 401 Newport Center Dr, Newport Beach, CA 92660, USA\\nGoogle place ID: ChIJUetYrofg3IARvxarZNginsY\\nPhone: (949) 721-2000\\nWebsite: https://www.fashionisland.com/?utm_source=soci&utm_medium=organic&utm_campaign=gmb_soci_listing\\n\\n\\n7. Haborland Fashion Island\\nAddress: ศูนย์การค้า แฟชั่นไอส์แลนด์ ชั้น3, Khwaeng Khan Na Yao, Khet Khan Na Yao, Krung Thep Maha Nakhon 10230, Thailand\\nGoogle place ID: ChIJ7wF25A5jHTERyBbgZ24hjGU\\nPhone: 065 848 1000\\nWebsite: https://harborlandgroup.com/\\n\\n\\n8. Panya Ramintra\\nAddress: Khan Na Yao, Bangkok 10230, Thailand\\nGoogle place ID: ChIJ9e97xwhjHTERR-MWDuKtUYY\\nPhone: Unknown\\nWebsite: Unknown\\n\\n\\n9. Manfair @Fashion Island, 2nd FL, Street 23, Grand Station, Unit MSE025\\nAddress: Manfair Store-Grand Station @Fashion Island Khwaeng Khan Na Yao, Khet Khan Na Yao, Krung Thep Maha Nakhon 10230, Thailand\\nGoogle place ID: ChIJod6zSApjHTERkZ8GxIKx-AY\\nPhone: 085 166 5561\\nWebsite: https://manfair.co.th/\\n\\n\\n10. ร้านชุดชั้นใน GIRLY SECRET @Fasion Island\\nAddress: GIRLY SECRET แฟชั่นไอส์แลนด์ ชั้น2 โซนแกรนด์เสตชั่น สตรีท 11 Lat Phrao Road Khwaeng Khan Na Yao, คันนายาว Krung Thep Maha Nakhon 10230, Thailand\\nGoogle place ID: ChIJMRAHkpKd4jARZBQhL3tzF28\\nPhone: 092 697 9698\\nWebsite: Unknown\\n\\n\\n11. OkurimonoJapan! (Fashion Island)\\nAddress: Level 2, Ram Inthra Rd, Khwaeng Khan Na Yao, Khet Khan Na Yao, Krung Thep Maha Nakhon 10230, Thailand\\nGoogle place ID: ChIJUTgHRlBjHTERw3I3e-uH7hI\\nPhone: 080 594 4644\\nWebsite: Unknown\\n\\n\\
|
43 |
]
|
44 |
},
|
45 |
"execution_count": 3,
|
@@ -56,7 +56,7 @@
|
|
56 |
},
|
57 |
{
|
58 |
"cell_type": "code",
|
59 |
-
"execution_count":
|
60 |
"metadata": {},
|
61 |
"outputs": [],
|
62 |
"source": [
|
@@ -66,19 +66,19 @@
|
|
66 |
},
|
67 |
{
|
68 |
"cell_type": "code",
|
69 |
-
"execution_count":
|
70 |
"metadata": {},
|
71 |
"outputs": [
|
72 |
{
|
73 |
"name": "stdout",
|
74 |
"output_type": "stream",
|
75 |
"text": [
|
76 |
-
"{'candidates': [{'formatted_address': '444 ถ. พญาไท แขวงวังใหม่ เขตปทุมวัน กรุงเทพมหานคร 10330 ไทย', 'geometry': {'location': {'lat': 13.744677, 'lng': 100.5295593}, 'viewport': {'northeast': {'lat': 13.74598387989272, 'lng': 100.5309299798927}, 'southwest': {'lat': 13.74328422010728, 'lng': 100.5282303201073}}}, 'name': 'เอ็ม บี เค เซ็นเตอร์', 'opening_hours': {'open_now':
|
77 |
]
|
78 |
}
|
79 |
],
|
80 |
"source": [
|
81 |
-
"def find_place_from_text(input_text, location=None, radius=
|
82 |
" # Retrieve the API key from environment variables\n",
|
83 |
" api_key = os.getenv('GPLACES_API_KEY')\n",
|
84 |
"\n",
|
|
|
2 |
"cells": [
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
"metadata": {},
|
7 |
"outputs": [],
|
8 |
"source": [
|
|
|
12 |
},
|
13 |
{
|
14 |
"cell_type": "code",
|
15 |
+
"execution_count": 2,
|
16 |
"metadata": {},
|
17 |
"outputs": [],
|
18 |
"source": [
|
|
|
39 |
{
|
40 |
"data": {
|
41 |
"text/plain": [
|
42 |
+
"'1. Fashion Island\\nAddress: 587-589/7-9, Ram Inthra Rd, Khwaeng Khan Na Yao, Khet Khan Na Yao, Krung Thep Maha Nakhon 10230, Thailand\\nGoogle place ID: ChIJd57HEQRjHTERG_xSTcdQoYs\\nPhone: 02 947 5000\\nWebsite: http://www.fashionisland.co.th/\\n\\n\\n2. Food Island-Fashion Island\\nAddress: 5/5-6 หมู่ 5 Fashion Island, Ram Inthra Rd, Khwaeng Khan Na Yao, บางเขน Krung Thep Maha Nakhon 10220, Thailand\\nGoogle place ID: ChIJxVlvKA9jHTERAaDXThEk0sU\\nPhone: Unknown\\nWebsite: https://www.fashionisland.co.th/\\n\\n\\n3. Grand Station @ Fashion Island\\nAddress: Fashion Island Shopping Mall คันนายาว Khet Khan Na Yao, Krung Thep Maha Nakhon 10230, Thailand\\nGoogle place ID: ChIJgYJ0xNxjHTERqh7EMAXGflk\\nPhone: 02 947 5000\\nWebsite: https://www.fashionisland.co.th/about-us/grandstation/\\n\\n\\n4. Central Department Store Fashion Island\\nAddress: 591 Ram Inthra Rd, Khwaeng Khan Na Yao, Khet Khan Na Yao, Krung Thep Maha Nakhon 10230, Thailand\\nGoogle place ID: ChIJU51oO09jHTERkAkthlfrvMQ\\nPhone: 02 947 5320\\nWebsite: http://www.central.co.th/\\n\\n\\n5. Pomelo Fashion Island\\nAddress: Unit GSSH101, 1st Floor, Fashion Island Shopping Mall, 587-589, Ramindra Rd, แขวงคันนายาว เขตคันนายาว กรุงเทพมหานคร 10230, Thailand\\nGoogle place ID: ChIJaYz1YRFjHTERHcxGtqrypsk\\nPhone: 02 000 6811\\nWebsite: https://www.pomelofashion.com/\\n\\n\\n6. Fashion Island\\nAddress: 401 Newport Center Dr, Newport Beach, CA 92660, USA\\nGoogle place ID: ChIJUetYrofg3IARvxarZNginsY\\nPhone: (949) 721-2000\\nWebsite: https://www.fashionisland.com/?utm_source=soci&utm_medium=organic&utm_campaign=gmb_soci_listing\\n\\n\\n7. Haborland Fashion Island\\nAddress: ศูนย์การค้า แฟชั่นไอส์แลนด์ ชั้น3, Khwaeng Khan Na Yao, Khet Khan Na Yao, Krung Thep Maha Nakhon 10230, Thailand\\nGoogle place ID: ChIJ7wF25A5jHTERyBbgZ24hjGU\\nPhone: 065 848 1000\\nWebsite: https://harborlandgroup.com/\\n\\n\\n8. Panya Ramintra\\nAddress: Khan Na Yao, Bangkok 10230, Thailand\\nGoogle place ID: ChIJ9e97xwhjHTERR-MWDuKtUYY\\nPhone: Unknown\\nWebsite: Unknown\\n\\n\\n9. Manfair @Fashion Island, 2nd FL, Street 23, Grand Station, Unit MSE025\\nAddress: Manfair Store-Grand Station @Fashion Island Khwaeng Khan Na Yao, Khet Khan Na Yao, Krung Thep Maha Nakhon 10230, Thailand\\nGoogle place ID: ChIJod6zSApjHTERkZ8GxIKx-AY\\nPhone: 085 166 5561\\nWebsite: https://manfair.co.th/\\n\\n\\n10. ร้านชุดชั้นใน GIRLY SECRET @Fasion Island\\nAddress: GIRLY SECRET แฟชั่นไอส์แลนด์ ชั้น2 โซนแกรนด์เสตชั่น สตรีท 11 Lat Phrao Road Khwaeng Khan Na Yao, คันนายาว Krung Thep Maha Nakhon 10230, Thailand\\nGoogle place ID: ChIJMRAHkpKd4jARZBQhL3tzF28\\nPhone: 092 697 9698\\nWebsite: Unknown\\n\\n\\n11. HomePro Fashion Island\\nAddress: 589, 10 Ram Inthra Rd, Khwaeng Khan Na Yao, Khet Khan Na Yao, Krung Thep Maha Nakhon 10230, Thailand\\nGoogle place ID: ChIJEyIpYLBjHTERibQeHSiSERE\\nPhone: 02 029 7700\\nWebsite: https://lin.ee/nfKDS60\\n\\n\\n12. OkurimonoJapan! (Fashion Island)\\nAddress: Level 2, Ram Inthra Rd, Khwaeng Khan Na Yao, Khet Khan Na Yao, Krung Thep Maha Nakhon 10230, Thailand\\nGoogle place ID: ChIJUTgHRlBjHTERw3I3e-uH7hI\\nPhone: 080 594 4644\\nWebsite: Unknown\\n\\n\\n13. Bake a Wish (Fashion Island)\\nAddress: ชั้น B, Fashion Island, 587 Ram Inthra Rd, รามอินทรา, Khet Khan Na Yao, Krung Thep Maha Nakhon 10230, Thailand\\nGoogle place ID: ChIJfyU40Q5jHTERTKLwRhRWk-o\\nPhone: 064 121 7146\\nWebsite: Unknown\\n\\n\\n14. Crush on Gelato สาขา Fasion island\\nAddress: RMGH+46W Fashion Island ชั้น 2 Staion B, Street 4, แขวงคันนายาว เขตคันนายาว กรุงเทพมหานคร 10230, Thailand\\nGoogle place ID: ChIJ69AOKABjHTERzQJJTyOunf4\\nPhone: 089 205 7502\\nWebsite: https://www.instagram.com/crush_on.gelato.bkk?igsh=azJiM3V4OGVscmpw\\n\\n\\n15. Opposite Fashion Island\\nAddress: Khan Na Yao, Bangkok 10230, Thailand\\nGoogle place ID: ChIJV8YMrwhjHTERTd8eEupPwZY\\nPhone: Unknown\\nWebsite: Unknown\\n\\n'"
|
43 |
]
|
44 |
},
|
45 |
"execution_count": 3,
|
|
|
56 |
},
|
57 |
{
|
58 |
"cell_type": "code",
|
59 |
+
"execution_count": 4,
|
60 |
"metadata": {},
|
61 |
"outputs": [],
|
62 |
"source": [
|
|
|
66 |
},
|
67 |
{
|
68 |
"cell_type": "code",
|
69 |
+
"execution_count": 6,
|
70 |
"metadata": {},
|
71 |
"outputs": [
|
72 |
{
|
73 |
"name": "stdout",
|
74 |
"output_type": "stream",
|
75 |
"text": [
|
76 |
+
"{'candidates': [{'formatted_address': '444 ถ. พญาไท แขวงวังใหม่ เขตปทุมวัน กรุงเทพมหานคร 10330 ไทย', 'geometry': {'location': {'lat': 13.744677, 'lng': 100.5295593}, 'viewport': {'northeast': {'lat': 13.74598387989272, 'lng': 100.5309299798927}, 'southwest': {'lat': 13.74328422010728, 'lng': 100.5282303201073}}}, 'name': 'เอ็ม บี เค เซ็นเตอร์', 'opening_hours': {'open_now': True}, 'rating': 4.3}], 'status': 'OK'}\n"
|
77 |
]
|
78 |
}
|
79 |
],
|
80 |
"source": [
|
81 |
+
"def find_place_from_text(input_text, location=None, radius=2000):\n",
|
82 |
" # Retrieve the API key from environment variables\n",
|
83 |
" api_key = os.getenv('GPLACES_API_KEY')\n",
|
84 |
"\n",
|
tools.ipynb
CHANGED
@@ -1,5 +1,75 @@
|
|
1 |
{
|
2 |
"cells": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
{
|
4 |
"cell_type": "code",
|
5 |
"execution_count": 1,
|
@@ -7,15 +77,13 @@
|
|
7 |
"outputs": [],
|
8 |
"source": [
|
9 |
"# gplace_tools.py\n",
|
10 |
-
"from gplace import find_place_from_text, find_location, nearby_search\n",
|
11 |
"from langgraph.prebuilt import ToolNode\n",
|
12 |
"from langchain_core.tools import tool\n",
|
13 |
"\n",
|
14 |
"find_place_from_text = tool(find_place_from_text)\n",
|
15 |
-
"find_location = tool(find_location)\n",
|
16 |
"nearby_search = tool(nearby_search)\n",
|
17 |
"\n",
|
18 |
-
"tools = [find_place_from_text,
|
19 |
"\n",
|
20 |
"# Create ToolNodes for each tool\n",
|
21 |
"tool_node = ToolNode(tools)"
|
|
|
1 |
{
|
2 |
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 2,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [],
|
8 |
+
"source": [
|
9 |
+
"import gplace\n",
|
10 |
+
"\n",
|
11 |
+
"location = \"13.744677,100.5295593\" # Latitude and Longitude\n",
|
12 |
+
"keyword = \"ร้านกาแฟ\"\n",
|
13 |
+
"result = gplace.nearby_search(keyword, location)"
|
14 |
+
]
|
15 |
+
},
|
16 |
+
{
|
17 |
+
"cell_type": "code",
|
18 |
+
"execution_count": 3,
|
19 |
+
"metadata": {},
|
20 |
+
"outputs": [],
|
21 |
+
"source": [
|
22 |
+
"def find_place_from_text(location:str):\n",
|
23 |
+
" \"\"\"Finds a place and related data from the query text\"\"\"\n",
|
24 |
+
" \n",
|
25 |
+
" result = gplace.find_place_from_text(location)\n",
|
26 |
+
" r = result['candidates'][0]\n",
|
27 |
+
" return f\"\"\"\n",
|
28 |
+
" address: {r['formatted_address']}\\n\n",
|
29 |
+
" location: {r['geometry']['location']}\\n\n",
|
30 |
+
" name: {r['name']}\\n\n",
|
31 |
+
" opening hours: {r['opening_hours']}\\n\n",
|
32 |
+
" rating: {r['rating']}\\n\n",
|
33 |
+
" \"\"\"\n",
|
34 |
+
" \n",
|
35 |
+
"def nearby_search(keyword:str, location:str, radius=2000, place_type=None):\n",
|
36 |
+
" \"\"\"Searches for many places nearby the location based on a keyword. using keyword like \\\"coffee shop\\\", \\\"restaurants\\\". radius is the range to search from the location\"\"\"\n",
|
37 |
+
" location = gplace.find_location(location, radius=radius)\n",
|
38 |
+
" result = gplace.nearby_search(keyword, location, radius)\n",
|
39 |
+
" \n",
|
40 |
+
" strout = \"\"\n",
|
41 |
+
" for r in result:\n",
|
42 |
+
" strout = strout + f\"\"\"\n",
|
43 |
+
" address: {r['vicinity']}\\n\n",
|
44 |
+
" location: {r['geometry']['location']}\\n\n",
|
45 |
+
" name: {r['name']}\\n\n",
|
46 |
+
" opening hours: {r['opening_hours']}\\n\n",
|
47 |
+
" rating: {r['rating']}\\n\n",
|
48 |
+
" plus code: {r['plus_code']['global_code']}\\n\\n\n",
|
49 |
+
" \"\"\"\n",
|
50 |
+
" return strout"
|
51 |
+
]
|
52 |
+
},
|
53 |
+
{
|
54 |
+
"cell_type": "code",
|
55 |
+
"execution_count": 4,
|
56 |
+
"metadata": {},
|
57 |
+
"outputs": [
|
58 |
+
{
|
59 |
+
"data": {
|
60 |
+
"text/plain": [
|
61 |
+
"\"\\n address: 587-589/7-9 ถ. รามอินทรา แขวงคันนายาว เขตคันนายาว กรุงเทพมหานคร 10230 ไทย\\n\\n location: {'lat': 13.8261789, 'lng': 100.6794462}\\n\\n name: แฟชั่นไอส์แลนด์\\n\\n opening hours: {'open_now': True}\\n\\n rating: 4.5\\n\\n \""
|
62 |
+
]
|
63 |
+
},
|
64 |
+
"execution_count": 4,
|
65 |
+
"metadata": {},
|
66 |
+
"output_type": "execute_result"
|
67 |
+
}
|
68 |
+
],
|
69 |
+
"source": [
|
70 |
+
"find_place_from_text(\"fashion island\")"
|
71 |
+
]
|
72 |
+
},
|
73 |
{
|
74 |
"cell_type": "code",
|
75 |
"execution_count": 1,
|
|
|
77 |
"outputs": [],
|
78 |
"source": [
|
79 |
"# gplace_tools.py\n",
|
|
|
80 |
"from langgraph.prebuilt import ToolNode\n",
|
81 |
"from langchain_core.tools import tool\n",
|
82 |
"\n",
|
83 |
"find_place_from_text = tool(find_place_from_text)\n",
|
|
|
84 |
"nearby_search = tool(nearby_search)\n",
|
85 |
"\n",
|
86 |
+
"tools = [find_place_from_text, nearby_search]\n",
|
87 |
"\n",
|
88 |
"# Create ToolNodes for each tool\n",
|
89 |
"tool_node = ToolNode(tools)"
|
tools.py
CHANGED
@@ -1,12 +1,45 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
from langgraph.prebuilt import ToolNode
|
3 |
from langchain_core.tools import tool
|
4 |
|
5 |
find_place_from_text = tool(find_place_from_text)
|
6 |
-
find_location = tool(find_location)
|
7 |
nearby_search = tool(nearby_search)
|
8 |
|
9 |
-
tools = [find_place_from_text,
|
10 |
|
11 |
# Create ToolNodes for each tool
|
12 |
tool_node = ToolNode(tools)
|
|
|
1 |
+
import gplace
|
2 |
+
|
3 |
+
# %%
|
4 |
+
def find_place_from_text(location:str):
|
5 |
+
"""Finds a place and related data from the query text"""
|
6 |
+
|
7 |
+
result = gplace.find_place_from_text(location)
|
8 |
+
r = result['candidates'][0]
|
9 |
+
return f"""
|
10 |
+
address: {r['formatted_address']}\n
|
11 |
+
location: {r['geometry']['location']}\n
|
12 |
+
name: {r['name']}\n
|
13 |
+
opening hours: {r['opening_hours']}\n
|
14 |
+
rating: {r['rating']}\n
|
15 |
+
"""
|
16 |
+
|
17 |
+
def nearby_search(keyword:str, location:str, radius=2000, place_type=None):
|
18 |
+
"""Searches for many places nearby the location based on a keyword. using keyword like \"coffee shop\", \"restaurants\". radius is the range to search from the location"""
|
19 |
+
location = gplace.find_location(location, radius=radius)
|
20 |
+
result = gplace.nearby_search(keyword, location, radius)
|
21 |
+
|
22 |
+
strout = ""
|
23 |
+
for r in result:
|
24 |
+
strout = strout + f"""
|
25 |
+
address: {r['vicinity']}\n
|
26 |
+
location: {r['geometry']['location']}\n
|
27 |
+
name: {r['name']}\n
|
28 |
+
opening hours: {r['opening_hours']}\n
|
29 |
+
rating: {r['rating']}\n
|
30 |
+
plus code: {r['plus_code']['global_code']}\n\n
|
31 |
+
"""
|
32 |
+
return strout
|
33 |
+
|
34 |
+
# %%
|
35 |
+
# gplace_tools.py
|
36 |
from langgraph.prebuilt import ToolNode
|
37 |
from langchain_core.tools import tool
|
38 |
|
39 |
find_place_from_text = tool(find_place_from_text)
|
|
|
40 |
nearby_search = tool(nearby_search)
|
41 |
|
42 |
+
tools = [find_place_from_text, nearby_search]
|
43 |
|
44 |
# Create ToolNodes for each tool
|
45 |
tool_node = ToolNode(tools)
|