ariankhalfani commited on
Commit
c00a199
1 Parent(s): 71c8c81

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -260,13 +260,18 @@ def view_db_interface():
260
  # Download Function
261
  def download_interface(choice):
262
  try:
 
263
  file_path = download_file(choice)
 
 
264
  with open(file_path, "rb") as file:
265
- return file.read(), file_path.split('/')[-1]
 
 
266
  except FileNotFoundError as e:
267
- return str(e), None
268
  except ValueError as e:
269
- return str(e), None
270
 
271
  # Gradio Blocks
272
  with gr.Blocks() as demo:
 
260
  # Download Function
261
  def download_interface(choice):
262
  try:
263
+ # Get the file path
264
  file_path = download_file(choice)
265
+
266
+ # Open the file in binary mode and return its content along with the filename
267
  with open(file_path, "rb") as file:
268
+ file_content = file.read()
269
+ file_name = os.path.basename(file_path)
270
+ return file_content, file_name # Return as a tuple for Gradio file component
271
  except FileNotFoundError as e:
272
+ return str(e), None # Handle file not found error gracefully
273
  except ValueError as e:
274
+ return str(e), None # Handle any value errors (e.g., invalid choice)
275
 
276
  # Gradio Blocks
277
  with gr.Blocks() as demo: