DreamStream-1 commited on
Commit
fffdb25
·
verified ·
1 Parent(s): 9c9023b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -24
app.py CHANGED
@@ -1,25 +1,15 @@
1
  import os
2
- import hashlib
3
- import hmac
4
- import urllib.parse
5
  import requests
6
  import gradio as gr
7
  import pandas as pd
8
 
9
- # Retrieve API key and URL signing secret from environment variables
10
- api_key = os.getenv("GOOGLE_API_KEY")
11
- url_signing_secret = os.getenv("GOOGLE_URL_SIGNING_SECRET")
12
 
13
  # Google Places API endpoints
14
  url = "https://maps.googleapis.com/maps/api/place/textsearch/json"
15
  places_details_url = "https://maps.googleapis.com/maps/api/place/details/json"
16
 
17
- # Function to generate signature for a URL
18
- def generate_signature(base_url, secret):
19
- secret_bytes = bytes(urllib.parse.unquote(secret), 'utf-8')
20
- signature = hmac.new(secret_bytes, msg=base_url.encode('utf-8'), digestmod=hashlib.sha1).hexdigest()
21
- return signature
22
-
23
  # Function to send a request to Google Places API and fetch places data
24
  def get_places_data(query, location, radius, next_page_token=None):
25
  params = {
@@ -32,11 +22,7 @@ def get_places_data(query, location, radius, next_page_token=None):
32
  if next_page_token:
33
  params["pagetoken"] = next_page_token
34
 
35
- base_url = f"{url}?{'&'.join([f'{k}={v}' for k, v in params.items()])}"
36
- signature = generate_signature(base_url, url_signing_secret)
37
- full_url = f"{base_url}&signature={signature}"
38
-
39
- response = requests.get(full_url)
40
 
41
  if response.status_code == 200:
42
  return response.json()
@@ -49,11 +35,7 @@ def get_place_details(place_id):
49
  "place_id": place_id,
50
  "key": api_key
51
  }
52
- base_url = f"{places_details_url}?{'&'.join([f'{k}={v}' for k, v in params.items()])}"
53
- signature = generate_signature(base_url, url_signing_secret)
54
- full_url = f"{base_url}&signature={signature}"
55
-
56
- response = requests.get(full_url)
57
 
58
  if response.status_code == 200:
59
  details_data = response.json().get("result", {})
@@ -103,5 +85,5 @@ iface = gr.Interface(
103
  description="Enter the search query, location coordinates, and radius to fetch wellness professionals from Google Places API."
104
  )
105
 
106
- # Run the Gradio interface
107
- iface.launch()
 
1
  import os
 
 
 
2
  import requests
3
  import gradio as gr
4
  import pandas as pd
5
 
6
+ # Google Maps API Key (replace with your actual key)
7
+ api_key = "GOOGLE_MAPS_API_KEY"
 
8
 
9
  # Google Places API endpoints
10
  url = "https://maps.googleapis.com/maps/api/place/textsearch/json"
11
  places_details_url = "https://maps.googleapis.com/maps/api/place/details/json"
12
 
 
 
 
 
 
 
13
  # Function to send a request to Google Places API and fetch places data
14
  def get_places_data(query, location, radius, next_page_token=None):
15
  params = {
 
22
  if next_page_token:
23
  params["pagetoken"] = next_page_token
24
 
25
+ response = requests.get(url, params=params)
 
 
 
 
26
 
27
  if response.status_code == 200:
28
  return response.json()
 
35
  "place_id": place_id,
36
  "key": api_key
37
  }
38
+ response = requests.get(places_details_url, params=params)
 
 
 
 
39
 
40
  if response.status_code == 200:
41
  details_data = response.json().get("result", {})
 
85
  description="Enter the search query, location coordinates, and radius to fetch wellness professionals from Google Places API."
86
  )
87
 
88
+ # Run the Gradio interface with sharing enabled
89
+ iface.launch(share=True)