Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -155,80 +155,38 @@ def detect_emotion(user_input):
|
|
155 |
|
156 |
return emotion_msg, resources, video_link
|
157 |
|
|
|
|
|
|
|
158 |
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
params = {
|
164 |
-
"address": location,
|
165 |
-
"key": api_key
|
166 |
-
}
|
167 |
-
response = requests.get(geocode_url, params=params)
|
168 |
-
if response.status_code == 200:
|
169 |
-
result = response.json()
|
170 |
-
if result['status'] == 'OK':
|
171 |
-
# Return the first result's latitude and longitude
|
172 |
-
location = result['results'][0]['geometry']['location']
|
173 |
-
return location['lat'], location['lng']
|
174 |
-
return None, None
|
175 |
-
|
176 |
-
# Google Places API setup for wellness professionals
|
177 |
-
url = "https://maps.googleapis.com/maps/api/place/textsearch/json"
|
178 |
-
places_details_url = "https://maps.googleapis.com/maps/api/place/details/json"
|
179 |
-
api_key = os.getenv("GOOGLE_API_KEY") # Use environment variable for security
|
180 |
-
|
181 |
-
# Function to get places data using Google Places API
|
182 |
-
def get_places_data(query, location, radius, api_key, next_page_token=None):
|
183 |
-
params = {
|
184 |
-
"query": query,
|
185 |
-
"location": location,
|
186 |
-
"radius": radius,
|
187 |
-
"key": api_key
|
188 |
-
}
|
189 |
-
|
190 |
-
if next_page_token:
|
191 |
-
params["pagetoken"] = next_page_token
|
192 |
-
|
193 |
-
response = requests.get(url, params=params)
|
194 |
-
if response.status_code == 200:
|
195 |
-
return response.json()
|
196 |
-
else:
|
197 |
-
return None
|
198 |
-
|
199 |
-
# Web scraping function to get wellness professional data (alternative to API)
|
200 |
-
def scrape_wellness_professionals(query, location):
|
201 |
-
# User-Agent header to simulate a browser request
|
202 |
-
headers = {
|
203 |
-
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
|
204 |
-
}
|
205 |
|
206 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
results = []
|
218 |
-
for div in result_divs:
|
219 |
-
name = div.get_text()
|
220 |
-
link = div.find("a")["href"]
|
221 |
-
results.append({"name": name, "link": link})
|
222 |
-
|
223 |
-
return results
|
224 |
-
else:
|
225 |
-
return None
|
226 |
-
|
227 |
-
# Initialize the chatbot interface
|
228 |
iface = gr.Interface(
|
229 |
-
fn=
|
230 |
-
inputs=["
|
231 |
-
|
|
|
|
|
232 |
allow_flagging="never",
|
233 |
live=True
|
234 |
)
|
|
|
155 |
|
156 |
return emotion_msg, resources, video_link
|
157 |
|
158 |
+
# Create the interface with multiple buttons
|
159 |
+
def interface_function(message, action, history):
|
160 |
+
history = history or []
|
161 |
|
162 |
+
if action == "Chat":
|
163 |
+
# Use chat function if 'Chat' button is clicked
|
164 |
+
history, _ = chat(message, history)
|
165 |
+
return history, history
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
|
167 |
+
elif action == "Detect Emotion":
|
168 |
+
# Detect emotion if 'Detect Emotion' button is clicked
|
169 |
+
emotion_msg, resources, video_link = detect_emotion(message)
|
170 |
+
result = f"Emotion: {emotion_msg}\nResources:\n"
|
171 |
+
for res in resources:
|
172 |
+
result += f"- {res['subject']}: {res['link']}\n"
|
173 |
+
result += f"Suggested Video: {video_link}"
|
174 |
+
return result, history
|
175 |
|
176 |
+
elif action == "Wellness Resources":
|
177 |
+
# Return wellness resources if 'Wellness Resources' button is clicked
|
178 |
+
result = "Here are some wellness resources you can explore:\n"
|
179 |
+
result += "1. Mental Health Support: https://www.helpguide.org/mental-health/mental-health-support.htm\n"
|
180 |
+
result += "2. Meditation Guide: https://www.headspace.com/meditation\n"
|
181 |
+
return result, history
|
182 |
+
|
183 |
+
# Gradio interface with multiple buttons
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
iface = gr.Interface(
|
185 |
+
fn=interface_function,
|
186 |
+
inputs=[gr.Textbox(label="Enter message"),
|
187 |
+
gr.Radio(["Chat", "Detect Emotion", "Wellness Resources"], label="Choose Action"),
|
188 |
+
gr.State()],
|
189 |
+
outputs=[gr.Textbox(label="Response"), gr.State()],
|
190 |
allow_flagging="never",
|
191 |
live=True
|
192 |
)
|