Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,14 +10,8 @@ from nltk.tokenize import word_tokenize
|
|
10 |
from nltk.stem.lancaster import LancasterStemmer
|
11 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
12 |
import requests
|
13 |
-
import re
|
14 |
from bs4 import BeautifulSoup
|
15 |
-
import time
|
16 |
import pandas as pd
|
17 |
-
from selenium import webdriver
|
18 |
-
from selenium.webdriver.chrome.options import Options
|
19 |
-
import chromedriver_autoinstaller
|
20 |
-
import os
|
21 |
import geocoder # Use geocoder to get latitude/longitude from city
|
22 |
|
23 |
# Ensure necessary NLTK resources are downloaded
|
@@ -212,89 +206,38 @@ def find_wellness_professionals(location, state):
|
|
212 |
|
213 |
google_places_data = get_all_places(query, location_coords, radius, api_key)
|
214 |
if google_places_data:
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
"Opening Hours", "Reviews", "Email"
|
219 |
-
])
|
220 |
-
# Display results in Gradio interface
|
221 |
-
if not df.empty:
|
222 |
-
df_html = df.to_html(classes="table table-striped", index=False)
|
223 |
-
return f"Found wellness professionals in your area: \n{df_html}", state
|
224 |
-
else:
|
225 |
-
return "No wellness professionals found for your location. Try another search.", state
|
226 |
else:
|
227 |
-
|
|
|
|
|
228 |
|
229 |
-
#
|
230 |
def get_all_places(query, location, radius, api_key):
|
231 |
-
|
232 |
-
response = requests.get(
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
name = place.get("name")
|
238 |
-
address = place.get("formatted_address")
|
239 |
-
phone = place.get("formatted_phone_number", "Not available")
|
240 |
-
rating = place.get("rating", "Not rated")
|
241 |
-
business_status = place.get("business_status", "N/A")
|
242 |
-
user_ratings_total = place.get("user_ratings_total", "N/A")
|
243 |
-
website = place.get("website", "Not available")
|
244 |
-
types = place.get("types", [])
|
245 |
-
lat, lng = place.get("geometry", {}).get("location", {}).values()
|
246 |
-
opening_hours = place.get("opening_hours", {}).get("weekday_text", [])
|
247 |
-
reviews = place.get("reviews", [])
|
248 |
-
email = "Not available" # Assume email is not included in the API response
|
249 |
-
|
250 |
-
# Adding the place data to the list
|
251 |
-
places.append([name, address, phone, rating, business_status, user_ratings_total,
|
252 |
-
website, types, lat, lng, opening_hours, reviews, email])
|
253 |
-
return places
|
254 |
-
else:
|
255 |
-
return []
|
256 |
|
257 |
-
# Gradio
|
258 |
-
def
|
259 |
with gr.Blocks() as demo:
|
260 |
-
|
261 |
-
gr.
|
262 |
-
gr.
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
# Chat interface
|
268 |
-
with gr.Row():
|
269 |
-
chatbot = gr.Chatbot(label="Chatbot")
|
270 |
-
user_input = gr.Textbox(placeholder="Type your message here...", label="Your Message")
|
271 |
-
send_button = gr.Button("Send")
|
272 |
-
|
273 |
-
# Output for emotion, sentiment, suggestions
|
274 |
-
with gr.Row():
|
275 |
-
sentiment_output = gr.Textbox(label="Sentiment Analysis")
|
276 |
-
emotion_output = gr.Textbox(label="Emotion Detection")
|
277 |
-
suggestions_output = gr.Textbox(label="Suggestions")
|
278 |
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
send_button.click(analyze_sentiment, inputs=[user_input, state], outputs=[sentiment_output, state])
|
289 |
-
user_input.submit(analyze_sentiment, inputs=[user_input, state], outputs=[sentiment_output, state])
|
290 |
-
|
291 |
-
send_button.click(detect_emotion, inputs=[user_input, state], outputs=[emotion_output, suggestions_output, state])
|
292 |
-
user_input.submit(detect_emotion, inputs=[user_input, state], outputs=[emotion_output, suggestions_output, state])
|
293 |
-
|
294 |
-
search_button.click(find_wellness_professionals, inputs=[location_input, state], outputs=[suggestions_output, state])
|
295 |
-
|
296 |
-
demo.launch(debug=True)
|
297 |
-
|
298 |
-
# Run the Gradio interface
|
299 |
-
if __name__ == "__main__":
|
300 |
-
gradio_interface()
|
|
|
10 |
from nltk.stem.lancaster import LancasterStemmer
|
11 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
12 |
import requests
|
|
|
13 |
from bs4 import BeautifulSoup
|
|
|
14 |
import pandas as pd
|
|
|
|
|
|
|
|
|
15 |
import geocoder # Use geocoder to get latitude/longitude from city
|
16 |
|
17 |
# Ensure necessary NLTK resources are downloaded
|
|
|
206 |
|
207 |
google_places_data = get_all_places(query, location_coords, radius, api_key)
|
208 |
if google_places_data:
|
209 |
+
response = "Wellness professionals near you:\n"
|
210 |
+
for place in google_places_data:
|
211 |
+
response += f"- {place['name']} at {place['formatted_address']}\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
212 |
else:
|
213 |
+
response = "Sorry, no wellness professionals found in your area. Please try another location."
|
214 |
+
|
215 |
+
return response, state
|
216 |
|
217 |
+
# Call Google Places API
|
218 |
def get_all_places(query, location, radius, api_key):
|
219 |
+
search_url = f"https://maps.googleapis.com/maps/api/place/textsearch/json?query={query}&location={location}&radius={radius}&key={api_key}"
|
220 |
+
response = requests.get(search_url).json()
|
221 |
+
|
222 |
+
if 'results' in response:
|
223 |
+
return response['results']
|
224 |
+
return []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
|
226 |
+
# Gradio UI components
|
227 |
+
def create_ui():
|
228 |
with gr.Blocks() as demo:
|
229 |
+
state = gr.State()
|
230 |
+
chatbot = gr.Chatbot(elem_id="chatbot", label="Mental Health Chatbot")
|
231 |
+
message_input = gr.Textbox(placeholder="Ask me something...", label="Enter your message")
|
232 |
+
sentiment_output = gr.Textbox(placeholder="Sentiment result", label="Sentiment")
|
233 |
+
emotion_output = gr.Textbox(placeholder="Detected emotion", label="Emotion")
|
234 |
+
wellness_output = gr.Textbox(placeholder="Wellness professional list", label="Wellness Professionals")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
|
236 |
+
message_input.submit(chat, [message_input, chatbot, state], [chatbot, chatbot, state])
|
237 |
+
message_input.submit(analyze_sentiment, [message_input, state], [sentiment_output, state])
|
238 |
+
sentiment_output.submit(detect_emotion, [sentiment_output, state], [emotion_output, wellness_output, state])
|
239 |
+
return demo
|
240 |
+
|
241 |
+
# Launch the Gradio interface
|
242 |
+
demo = create_ui()
|
243 |
+
demo.launch(debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|