Spaces:
Runtime error
Runtime error
Removed try-except
Browse files
app.py
CHANGED
@@ -15,50 +15,50 @@ from langchain_community.llms.huggingface_endpoint import HuggingFaceEndpoint
|
|
15 |
app = Flask(__name__)
|
16 |
|
17 |
|
18 |
-
try:
|
19 |
-
|
20 |
-
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
|
34 |
-
except Exception as e:
|
35 |
-
|
36 |
|
37 |
def process_query(query):
|
38 |
# os.system("cls")
|
39 |
|
40 |
-
try:
|
41 |
-
|
42 |
|
43 |
-
|
44 |
|
45 |
-
|
46 |
-
except Exception as e:
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
|
51 |
@app.route('/query', methods=['POST'])
|
52 |
def process_request():
|
53 |
|
54 |
-
try:
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
except Exception as e:
|
60 |
-
|
61 |
-
|
62 |
|
63 |
## Development phase use case only
|
64 |
# if __name__ == '__main__':
|
|
|
15 |
app = Flask(__name__)
|
16 |
|
17 |
|
18 |
+
# try:
|
19 |
+
loader = TextLoader("./data/app.txt")
|
20 |
+
document = loader.load()
|
21 |
|
22 |
+
# Split the document into chunks
|
23 |
+
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
24 |
+
docs = text_splitter.split_documents(document)
|
25 |
|
26 |
+
# Create embeddings
|
27 |
+
embedding = HuggingFaceEmbeddings(model_name = "sentence-transformers/all-mpnet-base-v2")
|
28 |
+
db = FAISS.from_documents(docs, embedding)
|
29 |
|
30 |
+
# Load the Question-Answering chain
|
31 |
+
llm = HuggingFaceEndpoint(repo_id="google/flan-t5-xxl", temperature=0.8, model_kwargs={"max_length": 512})
|
32 |
+
chain = load_qa_chain(llm, chain_type="stuff")
|
33 |
|
34 |
+
# except Exception as e:
|
35 |
+
# print("Recived Setup error: ", e)
|
36 |
|
37 |
def process_query(query):
|
38 |
# os.system("cls")
|
39 |
|
40 |
+
# try:
|
41 |
+
querySimilarDocs = db.similarity_search(query)
|
42 |
|
43 |
+
res = chain.run(input_documents = querySimilarDocs, question = query)
|
44 |
|
45 |
+
return res
|
46 |
+
# except Exception as e:
|
47 |
+
# print("Received process error: ", e)
|
48 |
+
# # return "An Error occurred!!"
|
49 |
+
# return e
|
50 |
|
51 |
@app.route('/query', methods=['POST'])
|
52 |
def process_request():
|
53 |
|
54 |
+
# try:
|
55 |
+
data = request.get_json()
|
56 |
+
user_input = data['query']
|
57 |
+
response = process_query(user_input)
|
58 |
+
return jsonify({"response": response})
|
59 |
+
# except Exception as e:
|
60 |
+
# print("Received Process request error: ", e)
|
61 |
+
# return jsonify({"response": str(e)})
|
62 |
|
63 |
## Development phase use case only
|
64 |
# if __name__ == '__main__':
|