Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -15,9 +15,7 @@ import torch
|
|
15 |
import pandas as pd
|
16 |
import time
|
17 |
from bs4 import BeautifulSoup
|
18 |
-
|
19 |
-
from selenium.webdriver.chrome.options import Options
|
20 |
-
import chromedriver_autoinstaller
|
21 |
import os
|
22 |
|
23 |
# Google Places API endpoint
|
@@ -46,7 +44,6 @@ model = tflearn.DNN(net)
|
|
46 |
model.load("MentalHealthChatBotmodel.tflearn")
|
47 |
|
48 |
# Emotion and sentiment analysis model
|
49 |
-
@st.cache_resource
|
50 |
def load_model():
|
51 |
tokenizer = AutoTokenizer.from_pretrained("j-hartmann/emotion-english-distilroberta-base")
|
52 |
model = AutoModelForSequenceClassification.from_pretrained("j-hartmann/emotion-english-distilroberta-base")
|
@@ -65,7 +62,7 @@ def get_places_data(query, location, radius=5000, api_key="GOOGLE_API_KEY"):
|
|
65 |
response = requests.get(url, params=params)
|
66 |
if response.status_code == 200:
|
67 |
data = response.json()
|
68 |
-
return data
|
69 |
else:
|
70 |
return []
|
71 |
|
@@ -77,7 +74,7 @@ def create_map(locations):
|
|
77 |
lat = loc['geometry']['location']['lat']
|
78 |
lng = loc['geometry']['location']['lng']
|
79 |
folium.Marker([lat, lng], popup=name).add_to(m)
|
80 |
-
return m
|
81 |
|
82 |
# Sentiment Analysis function
|
83 |
def analyze_sentiment(user_input):
|
@@ -134,7 +131,7 @@ def scrape_website_for_contact_info(website):
|
|
134 |
try:
|
135 |
response = requests.get(website, timeout=5)
|
136 |
soup = BeautifulSoup(response.content, 'html.parser')
|
137 |
-
phone_match = re.search(r'
|
138 |
if phone_match:
|
139 |
phone_number = phone_match.group()
|
140 |
email_match = re.search(r'[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}', soup.get_text())
|
@@ -144,17 +141,6 @@ def scrape_website_for_contact_info(website):
|
|
144 |
print(f"Error scraping website {website}: {e}")
|
145 |
return phone_number, email
|
146 |
|
147 |
-
# Main Gradio interface for location search and map generation
|
148 |
-
def search_and_display_location(query, location):
|
149 |
-
query = query or "wellness"
|
150 |
-
location = location or "21.3,-157.8" # Default location (Hawaii)
|
151 |
-
places_data = get_places_data(query, location)
|
152 |
-
if places_data:
|
153 |
-
map_object = create_map(places_data)
|
154 |
-
return map_object
|
155 |
-
else:
|
156 |
-
return "No results found for the given location."
|
157 |
-
|
158 |
# Main Gradio interface for emotion detection and chatbot
|
159 |
def emotion_and_chatbot(user_input, history, query, location):
|
160 |
# Emotion Detection
|
@@ -165,7 +151,7 @@ def emotion_and_chatbot(user_input, history, query, location):
|
|
165 |
# Search Places (for wellness or other queries)
|
166 |
places_data = get_places_data(query, location)
|
167 |
places_map = create_map(places_data) if places_data else "No places found."
|
168 |
-
|
169 |
# Chatbot response
|
170 |
history, _ = chatbot(user_input, history)
|
171 |
|
@@ -192,4 +178,4 @@ iface = gr.Interface(
|
|
192 |
|
193 |
# Launch Gradio app
|
194 |
if __name__ == "__main__":
|
195 |
-
iface.launch(debug=True)
|
|
|
15 |
import pandas as pd
|
16 |
import time
|
17 |
from bs4 import BeautifulSoup
|
18 |
+
import re # Added for regex operations
|
|
|
|
|
19 |
import os
|
20 |
|
21 |
# Google Places API endpoint
|
|
|
44 |
model.load("MentalHealthChatBotmodel.tflearn")
|
45 |
|
46 |
# Emotion and sentiment analysis model
|
|
|
47 |
def load_model():
|
48 |
tokenizer = AutoTokenizer.from_pretrained("j-hartmann/emotion-english-distilroberta-base")
|
49 |
model = AutoModelForSequenceClassification.from_pretrained("j-hartmann/emotion-english-distilroberta-base")
|
|
|
62 |
response = requests.get(url, params=params)
|
63 |
if response.status_code == 200:
|
64 |
data = response.json()
|
65 |
+
return data.get('results', [])
|
66 |
else:
|
67 |
return []
|
68 |
|
|
|
74 |
lat = loc['geometry']['location']['lat']
|
75 |
lng = loc['geometry']['location']['lng']
|
76 |
folium.Marker([lat, lng], popup=name).add_to(m)
|
77 |
+
return m._repr_html_() # Return HTML representation
|
78 |
|
79 |
# Sentiment Analysis function
|
80 |
def analyze_sentiment(user_input):
|
|
|
131 |
try:
|
132 |
response = requests.get(website, timeout=5)
|
133 |
soup = BeautifulSoup(response.content, 'html.parser')
|
134 |
+
phone_match = re.search(r'$$?\+?[0-9]*$$?[0-9_\- $$$$]*', soup.get_text())
|
135 |
if phone_match:
|
136 |
phone_number = phone_match.group()
|
137 |
email_match = re.search(r'[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}', soup.get_text())
|
|
|
141 |
print(f"Error scraping website {website}: {e}")
|
142 |
return phone_number, email
|
143 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
# Main Gradio interface for emotion detection and chatbot
|
145 |
def emotion_and_chatbot(user_input, history, query, location):
|
146 |
# Emotion Detection
|
|
|
151 |
# Search Places (for wellness or other queries)
|
152 |
places_data = get_places_data(query, location)
|
153 |
places_map = create_map(places_data) if places_data else "No places found."
|
154 |
+
|
155 |
# Chatbot response
|
156 |
history, _ = chatbot(user_input, history)
|
157 |
|
|
|
178 |
|
179 |
# Launch Gradio app
|
180 |
if __name__ == "__main__":
|
181 |
+
iface.launch(debug=True)
|