DreamStream-1 commited on
Commit
1e5e00a
·
verified ·
1 Parent(s): 287d313

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -3
app.py CHANGED
@@ -18,6 +18,7 @@ from selenium import webdriver
18
  from selenium.webdriver.chrome.options import Options
19
  import chromedriver_autoinstaller
20
  import os
 
21
 
22
  # Ensure necessary NLTK resources are downloaded
23
  nltk.download('punkt')
@@ -166,11 +167,22 @@ def search_wellness_professionals(location):
166
  query = "therapist OR counselor OR mental health professional"
167
  radius = 50000
168
  google_places_data = get_all_places(query, location, radius, api_key)
 
 
169
  if google_places_data:
170
  df = pd.DataFrame(google_places_data, columns=["Name", "Address", "Website"])
171
- return df.to_csv(index=False)
 
 
 
 
172
  else:
173
- return "No data found."
 
 
 
 
 
174
 
175
  # Gradio Interface
176
  def gradio_interface(message, location, state):
@@ -216,4 +228,3 @@ iface = gr.Interface(
216
  # Launch Gradio interface
217
  if __name__ == "__main__":
218
  iface.launch(debug=True, share=True) # Set share=True to create a public link
219
-
 
18
  from selenium.webdriver.chrome.options import Options
19
  import chromedriver_autoinstaller
20
  import os
21
+ import io
22
 
23
  # Ensure necessary NLTK resources are downloaded
24
  nltk.download('punkt')
 
167
  query = "therapist OR counselor OR mental health professional"
168
  radius = 50000
169
  google_places_data = get_all_places(query, location, radius, api_key)
170
+
171
+ # Check if data is found
172
  if google_places_data:
173
  df = pd.DataFrame(google_places_data, columns=["Name", "Address", "Website"])
174
+ # Create a CSV in memory
175
+ csv_file = io.StringIO()
176
+ df.to_csv(csv_file, index=False)
177
+ csv_file.seek(0) # Reset the pointer to the beginning of the file
178
+ return csv_file # Return the file-like object
179
  else:
180
+ # If no data found, return a dummy CSV with a message
181
+ dummy_df = pd.DataFrame([["No data found.", "", ""]], columns=["Name", "Address", "Website"])
182
+ csv_file = io.StringIO()
183
+ dummy_df.to_csv(csv_file, index=False)
184
+ csv_file.seek(0)
185
+ return csv_file # Return the dummy file
186
 
187
  # Gradio Interface
188
  def gradio_interface(message, location, state):
 
228
  # Launch Gradio interface
229
  if __name__ == "__main__":
230
  iface.launch(debug=True, share=True) # Set share=True to create a public link