Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -67,30 +67,35 @@ def process_json():
|
|
67 |
@app.route('/file_upload',methods=['POST'])
|
68 |
def file_Upload():
|
69 |
|
70 |
-
|
71 |
-
|
72 |
-
print(
|
73 |
-
print(
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
try:
|
78 |
-
if os.path.isfile(file_path) or os.path.islink(file_path):
|
79 |
-
os.unlink(file_path)
|
80 |
-
elif os.path.isdir(file_path):
|
81 |
-
shutil.rmtree(file_path)
|
82 |
-
except Exception as e:
|
83 |
-
print('Failed to delete %s. Reason: %s' % (file_path, e))
|
84 |
-
|
85 |
documents = []
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
print(uploads_dir)
|
96 |
global chain;
|
|
|
67 |
@app.route('/file_upload',methods=['POST'])
|
68 |
def file_Upload():
|
69 |
|
70 |
+
fileprovided=not request.files.getlist('files[]')[0].filename==''
|
71 |
+
urlProvided=not request.form.getlist('weburl')[0]==''
|
72 |
+
print("*******")
|
73 |
+
print("File Provided:"+str(fileprovided))
|
74 |
+
print("URL Provided:"+str(urlProvided))
|
75 |
+
print("*******")
|
76 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
documents = []
|
78 |
+
if fileprovided:
|
79 |
+
#Delete Files
|
80 |
+
for filename in os.listdir(uploads_dir):
|
81 |
+
file_path = os.path.join(uploads_dir, filename)
|
82 |
+
print("Clearing Doc Directory. Trying to delete"+file_path)
|
83 |
+
try:
|
84 |
+
if os.path.isfile(file_path) or os.path.islink(file_path):
|
85 |
+
os.unlink(file_path)
|
86 |
+
elif os.path.isdir(file_path):
|
87 |
+
shutil.rmtree(file_path)
|
88 |
+
except Exception as e:
|
89 |
+
print('Failed to delete %s. Reason: %s' % (file_path, e))
|
90 |
+
#Read and Embed New Files provided
|
91 |
+
for file in request.files.getlist('files[]'):
|
92 |
+
print(file.filename)
|
93 |
+
file.save(os.path.join(uploads_dir, secure_filename(file.filename)))
|
94 |
+
loader = UnstructuredFileLoader(os.path.join(uploads_dir, secure_filename(file.filename)), mode='elements')
|
95 |
+
documents.extend(loader.load())
|
96 |
+
if urlProvided:
|
97 |
+
urlLoader=WebBaseLoader(request.form.getlist('weburl'))
|
98 |
+
documents.extend(urlLoader.load())
|
99 |
|
100 |
print(uploads_dir)
|
101 |
global chain;
|