ariankhalfani commited on
Commit
e6eaf4a
1 Parent(s): 59adf16

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -4
app.py CHANGED
@@ -201,23 +201,36 @@ def view_database():
201
 
202
  return html_content
203
 
204
- # Function to download database or image
205
  def download_file(choice):
206
  directory = "/mnt/data"
 
 
207
  if not os.path.exists(directory):
208
  os.makedirs(directory)
209
 
210
  if choice == "Database (.db)":
211
- return 'results.db'
 
 
 
212
  elif choice == "Database (.html)":
213
- conn = sqlite3.connect('results.db')
 
 
 
214
  df = pd.read_sql_query("SELECT * FROM results", conn)
 
 
215
  conn.close()
216
 
 
217
  html_file_path = os.path.join(directory, "results.html")
 
 
218
  df.to_html(html_file_path, index=False)
219
 
220
- return html_file_path # Ensure the path is returned as a string
221
 
222
  # Initialize the database
223
  init_db()
 
201
 
202
  return html_content
203
 
204
+ # Function to download database or HTML file
205
  def download_file(choice):
206
  directory = "/mnt/data"
207
+
208
+ # Ensure the directory exists
209
  if not os.path.exists(directory):
210
  os.makedirs(directory)
211
 
212
  if choice == "Database (.db)":
213
+ # Assuming the database is stored in the same directory
214
+ db_file_path = os.path.join(directory, 'results.db')
215
+ return db_file_path # Return the path as a string
216
+
217
  elif choice == "Database (.html)":
218
+ # Connect to the SQLite database
219
+ conn = sqlite3.connect(os.path.join(directory, 'results.db'))
220
+
221
+ # Read the database into a DataFrame
222
  df = pd.read_sql_query("SELECT * FROM results", conn)
223
+
224
+ # Close the database connection
225
  conn.close()
226
 
227
+ # Define the path for the HTML file
228
  html_file_path = os.path.join(directory, "results.html")
229
+
230
+ # Save the DataFrame as an HTML file
231
  df.to_html(html_file_path, index=False)
232
 
233
+ return html_file_path # Return the path as a string
234
 
235
  # Initialize the database
236
  init_db()