ariankhalfani commited on
Commit
2d00553
1 Parent(s): 803ff18

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -212,10 +212,14 @@ def download_file(choice):
212
  db_file_path = os.path.join(directory, 'results.db')
213
 
214
  if choice == "Database (.db)":
215
- # Simply return the path to the database file
216
  return db_file_path
217
 
218
  elif choice == "Database (.html)":
 
 
 
 
219
  # Connect to the SQLite database
220
  conn = sqlite3.connect(db_file_path)
221
 
@@ -223,7 +227,6 @@ def download_file(choice):
223
  # Attempt to read the results table into a DataFrame
224
  df = pd.read_sql_query("SELECT * FROM results", conn)
225
  except pd.errors.DatabaseError as e:
226
- # Handle the case where the table doesn't exist
227
  conn.close()
228
  raise ValueError("Table 'results' does not exist in the database.") from e
229
 
@@ -267,10 +270,9 @@ def download_interface(choice):
267
 
268
  # Return the file path (string) directly for the Gradio component to handle
269
  return file_path
270
- except FileNotFoundError as e:
271
- return str(e) # Handle file not found error gracefully
272
- except ValueError as e:
273
- return str(e) # Handle any value errors (e.g., invalid choice)
274
 
275
  # Gradio Blocks
276
  with gr.Blocks() as demo:
 
212
  db_file_path = os.path.join(directory, 'results.db')
213
 
214
  if choice == "Database (.db)":
215
+ # Return the correct database file path
216
  return db_file_path
217
 
218
  elif choice == "Database (.html)":
219
+ # Check if the database file exists
220
+ if not os.path.isfile(db_file_path):
221
+ raise FileNotFoundError(f"Database file not found at path: {db_file_path}")
222
+
223
  # Connect to the SQLite database
224
  conn = sqlite3.connect(db_file_path)
225
 
 
227
  # Attempt to read the results table into a DataFrame
228
  df = pd.read_sql_query("SELECT * FROM results", conn)
229
  except pd.errors.DatabaseError as e:
 
230
  conn.close()
231
  raise ValueError("Table 'results' does not exist in the database.") from e
232
 
 
270
 
271
  # Return the file path (string) directly for the Gradio component to handle
272
  return file_path
273
+ except (FileNotFoundError, ValueError) as e:
274
+ # Display error message in Gradio output
275
+ return str(e)
 
276
 
277
  # Gradio Blocks
278
  with gr.Blocks() as demo: