localsavageai commited on
Commit
c2715c9
·
verified ·
1 Parent(s): 9896ffc

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -212,11 +212,15 @@ with gr.Blocks() as app:
212
  if not file or not db_name or not password:
213
  return "Please provide all required inputs."
214
 
215
- # Read file content
216
- try:
217
- file_content = file.read().decode("utf-8")
218
- except Exception as e:
219
- return f"Error reading file: {str(e)}"
 
 
 
 
220
 
221
  return create_new_database(file_content, db_name, password)
222
 
 
212
  if not file or not db_name or not password:
213
  return "Please provide all required inputs."
214
 
215
+ # Check if the file is valid
216
+ if isinstance(file, str): # Gradio provides the file path as a string
217
+ try:
218
+ with open(file, "r", encoding="utf-8") as f:
219
+ file_content = f.read()
220
+ except Exception as e:
221
+ return f"Error reading file: {str(e)}"
222
+ else:
223
+ return "Invalid file format. Please upload a .txt file."
224
 
225
  return create_new_database(file_content, db_name, password)
226