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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -10
app.py CHANGED
@@ -18,7 +18,7 @@ from selenium import webdriver
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')
@@ -171,18 +171,23 @@ def search_wellness_professionals(location):
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):
 
18
  from selenium.webdriver.chrome.options import Options
19
  import chromedriver_autoinstaller
20
  import os
21
+ import tempfile
22
 
23
  # Ensure necessary NLTK resources are downloaded
24
  nltk.download('punkt')
 
171
  # Check if data is found
172
  if google_places_data:
173
  df = pd.DataFrame(google_places_data, columns=["Name", "Address", "Website"])
174
+
175
+ # Create a temporary file to store the CSV
176
+ temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".csv")
177
+ df.to_csv(temp_file, index=False)
178
+ temp_file.close() # Close the file so that Gradio can download it
179
+
180
+ return temp_file.name # Return the path to the temporary file
181
  else:
182
  # If no data found, return a dummy CSV with a message
183
  dummy_df = pd.DataFrame([["No data found.", "", ""]], columns=["Name", "Address", "Website"])
184
+
185
+ # Create a temporary file for the dummy data
186
+ temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".csv")
187
+ dummy_df.to_csv(temp_file, index=False)
188
+ temp_file.close() # Close the file
189
+
190
+ return temp_file.name # Return the path to the dummy file
191
 
192
  # Gradio Interface
193
  def gradio_interface(message, location, state):