Spaces:
Sleeping
Sleeping
helloguddn (PC helloguddn)
feat: 의존성, chat 엔드포인트, gemini function calling, 이미지 추출, Maps 연동, 노동법 RAG(google.text-embedding-004)
f4bf832 Download services/google_maps_service.py from helloguddn/Suwon_multiculturalism: direct link, hf CLI and curl.
- Browser
- Download file 1.09 kB
-
https://huggingface.co/spaces/helloguddn/Suwon_multiculturalism/resolve/main/services/google_maps_service.py
- Command line
-
hf download hf://spaces/helloguddn/Suwon_multiculturalism/services/google_maps_service.py
-
curl -L -o google_maps_service.py https://huggingface.co/spaces/helloguddn/Suwon_multiculturalism/resolve/main/services/google_maps_service.py
1.09 kB
| import os | |
| import googlemaps | |
| _client: googlemaps.Client | None = None | |
| def get_client() -> googlemaps.Client: | |
| global _client | |
| if _client is None: | |
| api_key = os.getenv("GOOGLE_MAPS_API_KEY") | |
| if not api_key: | |
| raise RuntimeError("GOOGLE_MAPS_API_KEY environment variable is not set") | |
| _client = googlemaps.Client(key=api_key) | |
| return _client | |
| def search_nearby( | |
| lat: float, | |
| lng: float, | |
| keyword: str, | |
| radius: int = 5000, | |
| ) -> list[dict]: | |
| client = get_client() | |
| result = client.places_nearby( | |
| location=(lat, lng), | |
| radius=radius, | |
| keyword=keyword, | |
| language="ko", | |
| ) | |
| places = [] | |
| for place in result.get("results", [])[:5]: | |
| loc = place["geometry"]["location"] | |
| places.append( | |
| { | |
| "name": place.get("name", ""), | |
| "lat": loc["lat"], | |
| "lng": loc["lng"], | |
| "address": place.get("vicinity", ""), | |
| "phone": place.get("formatted_phone_number", ""), | |
| } | |
| ) | |
| return places | |