Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -57,5 +57,34 @@ def process_json():
|
|
57 |
else:
|
58 |
return 'Content-Type not supported!'
|
59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
if __name__ == '__main__':
|
61 |
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
|
|
|
57 |
else:
|
58 |
return 'Content-Type not supported!'
|
59 |
|
60 |
+
|
61 |
+
@app.route('/file_upload',methods=['POST'])
|
62 |
+
def file_Upload():
|
63 |
+
|
64 |
+
#print(request.headers.get('Content-Type'))
|
65 |
+
file=request.files['file']
|
66 |
+
print(uploads_dir)
|
67 |
+
global chain;
|
68 |
+
|
69 |
+
|
70 |
+
file.save(os.path.join(uploads_dir, secure_filename(file.filename)))
|
71 |
+
loader = UnstructuredFileLoader(os.path.join(uploads_dir, secure_filename(file.filename)), mode='elements')
|
72 |
+
documents= loader.load()
|
73 |
+
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
74 |
+
texts = text_splitter.split_documents(documents)
|
75 |
+
embeddings = OpenAIEmbeddings()
|
76 |
+
doc_search = Chroma.from_documents(texts,embeddings)
|
77 |
+
chain = VectorDBQA.from_chain_type(llm=OpenAI(), chain_type="stuff", vectorstore=doc_search)
|
78 |
+
|
79 |
+
return render_template("AIAssist.html")
|
80 |
+
|
81 |
+
@app.route('/KBUploader')
|
82 |
+
def KBUpload():
|
83 |
+
return render_template("FileUpload.html")
|
84 |
+
|
85 |
+
@app.route('/aiassist')
|
86 |
+
def aiassist():
|
87 |
+
return render_template("AIAssist.html")
|
88 |
+
|
89 |
if __name__ == '__main__':
|
90 |
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
|