Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -98,6 +98,23 @@ def load_emotion_model():
|
|
98 |
|
99 |
tokenizer_emotion, model_emotion = load_emotion_model()
|
100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
# Google Places API setup for wellness professionals
|
102 |
url = "https://maps.googleapis.com/maps/api/place/textsearch/json"
|
103 |
places_details_url = "https://maps.googleapis.com/maps/api/place/details/json"
|
@@ -147,13 +164,19 @@ def scrape_wellness_professionals(query, location):
|
|
147 |
else:
|
148 |
return []
|
149 |
|
150 |
-
#
|
151 |
-
def get_wellness_professionals(location):
|
152 |
query = "therapist OR counselor OR mental health professional OR marriage and family therapist OR psychotherapist OR psychiatrist OR psychologist OR nutritionist OR wellness doctor OR holistic practitioner OR integrative medicine OR chiropractor OR naturopath"
|
153 |
radius = 50000 # 50 km radius
|
|
|
|
|
|
|
154 |
|
155 |
-
|
156 |
-
|
|
|
|
|
|
|
157 |
|
158 |
if data:
|
159 |
results = data.get('results', [])
|
@@ -219,7 +242,7 @@ def user_interface(message, location, history):
|
|
219 |
emotion_msg, resources, video_link = detect_emotion(message)
|
220 |
|
221 |
# Get wellness professionals
|
222 |
-
wellness_data = get_wellness_professionals(location)
|
223 |
|
224 |
# Display wellness professionals in a table format
|
225 |
wellness_df = pd.DataFrame(wellness_data, columns=["Name", "Address", "Latitude", "Longitude"])
|
|
|
98 |
|
99 |
tokenizer_emotion, model_emotion = load_emotion_model()
|
100 |
|
101 |
+
# Google Geocoding API setup to convert city name to latitude/longitude
|
102 |
+
geocode_url = "https://maps.googleapis.com/maps/api/geocode/json"
|
103 |
+
|
104 |
+
def get_lat_lon(location, api_key):
|
105 |
+
params = {
|
106 |
+
"address": location,
|
107 |
+
"key": api_key
|
108 |
+
}
|
109 |
+
response = requests.get(geocode_url, params=params)
|
110 |
+
if response.status_code == 200:
|
111 |
+
result = response.json()
|
112 |
+
if result['status'] == 'OK':
|
113 |
+
# Return the first result's latitude and longitude
|
114 |
+
location = result['results'][0]['geometry']['location']
|
115 |
+
return location['lat'], location['lng']
|
116 |
+
return None, None
|
117 |
+
|
118 |
# Google Places API setup for wellness professionals
|
119 |
url = "https://maps.googleapis.com/maps/api/place/textsearch/json"
|
120 |
places_details_url = "https://maps.googleapis.com/maps/api/place/details/json"
|
|
|
164 |
else:
|
165 |
return []
|
166 |
|
167 |
+
# Updated function to get wellness professionals
|
168 |
+
def get_wellness_professionals(location, api_key):
|
169 |
query = "therapist OR counselor OR mental health professional OR marriage and family therapist OR psychotherapist OR psychiatrist OR psychologist OR nutritionist OR wellness doctor OR holistic practitioner OR integrative medicine OR chiropractor OR naturopath"
|
170 |
radius = 50000 # 50 km radius
|
171 |
+
|
172 |
+
# Get the latitude and longitude from the location input
|
173 |
+
lat, lon = get_lat_lon(location, api_key)
|
174 |
|
175 |
+
if lat is None or lon is None:
|
176 |
+
return "Unable to find coordinates for the given location."
|
177 |
+
|
178 |
+
# Using Google Places API to fetch wellness professionals
|
179 |
+
data = get_places_data(query, f"{lat},{lon}", radius, api_key)
|
180 |
|
181 |
if data:
|
182 |
results = data.get('results', [])
|
|
|
242 |
emotion_msg, resources, video_link = detect_emotion(message)
|
243 |
|
244 |
# Get wellness professionals
|
245 |
+
wellness_data = get_wellness_professionals(location, api_key)
|
246 |
|
247 |
# Display wellness professionals in a table format
|
248 |
wellness_df = pd.DataFrame(wellness_data, columns=["Name", "Address", "Latitude", "Longitude"])
|