Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -66,21 +66,44 @@ def process_json():
|
|
| 66 |
|
| 67 |
@app.route('/file_upload',methods=['POST'])
|
| 68 |
def file_Upload():
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
print(uploads_dir)
|
| 73 |
global chain;
|
| 74 |
-
|
| 75 |
|
| 76 |
-
|
| 77 |
-
loader = UnstructuredFileLoader(os.path.join(uploads_dir, secure_filename(file.filename)), mode='elements')
|
| 78 |
-
documents= loader.load()
|
| 79 |
-
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
| 80 |
texts = text_splitter.split_documents(documents)
|
| 81 |
embeddings = OpenAIEmbeddings()
|
| 82 |
-
|
| 83 |
-
chain =
|
| 84 |
|
| 85 |
return render_template("index.html")
|
| 86 |
|
|
|
|
| 66 |
|
| 67 |
@app.route('/file_upload',methods=['POST'])
|
| 68 |
def file_Upload():
|
| 69 |
+
|
| 70 |
+
print(request.files.getlist('files[]'))
|
| 71 |
+
print(request.files)
|
| 72 |
+
print(request.form)
|
| 73 |
+
print(request.form.getlist('weburl'))
|
| 74 |
+
for filename in os.listdir(uploads_dir):
|
| 75 |
+
file_path = os.path.join(uploads_dir, filename)
|
| 76 |
+
print("Clearing Doc Directory. Trying to delete"+file_path)
|
| 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 |
+
for file in request.files.getlist('files[]'):
|
| 87 |
+
print(file.filename)
|
| 88 |
+
file.save(os.path.join(uploads_dir, secure_filename(file.filename)))
|
| 89 |
+
loader = UnstructuredFileLoader(os.path.join(uploads_dir, secure_filename(file.filename)), mode='elements')
|
| 90 |
+
documents.extend(loader.load())
|
| 91 |
+
|
| 92 |
+
print(request.form.getlist('weburl'))
|
| 93 |
+
for url in request.form.getlist('weburl'):
|
| 94 |
+
print(type(url))
|
| 95 |
+
urlLoader=WebBaseLoader(url)
|
| 96 |
+
documents.extend(urlLoader.load())
|
| 97 |
+
|
| 98 |
+
|
| 99 |
print(uploads_dir)
|
| 100 |
global chain;
|
|
|
|
| 101 |
|
| 102 |
+
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=100)
|
|
|
|
|
|
|
|
|
|
| 103 |
texts = text_splitter.split_documents(documents)
|
| 104 |
embeddings = OpenAIEmbeddings()
|
| 105 |
+
vectordb = Chroma.from_documents(texts,embeddings)
|
| 106 |
+
chain = RetrievalQA.from_chain_type(llm=OpenAI(temperature=0.0),chain_type="stuff", retriever=vectordb.as_retriever())
|
| 107 |
|
| 108 |
return render_template("index.html")
|
| 109 |
|