Spaces:
Runtime error
Runtime error
arjunanand13
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import os
|
2 |
import multiprocessing
|
|
|
3 |
from langchain.document_loaders import TextLoader, DirectoryLoader
|
4 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
5 |
from langchain.vectorstores import FAISS
|
@@ -62,12 +63,11 @@ class DocumentRetrievalAndGeneration:
|
|
62 |
|
63 |
def generate_response_with_timeout(self, model_inputs):
|
64 |
try:
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
generated_ids = result.get(timeout=80) # Timeout set to 60 seconds
|
69 |
return generated_ids
|
70 |
-
except
|
71 |
raise TimeoutError("Text generation process timed out")
|
72 |
|
73 |
def query_and_generate_response(self, query):
|
|
|
1 |
import os
|
2 |
import multiprocessing
|
3 |
+
import concurrent.futures
|
4 |
from langchain.document_loaders import TextLoader, DirectoryLoader
|
5 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
6 |
from langchain.vectorstores import FAISS
|
|
|
63 |
|
64 |
def generate_response_with_timeout(self, model_inputs):
|
65 |
try:
|
66 |
+
with concurrent.futures.ThreadPoolExecutor() as executor:
|
67 |
+
future = executor.submit(self.llm.model.generate, model_inputs, max_new_tokens=1000, do_sample=True)
|
68 |
+
generated_ids = future.result(timeout=60) # Timeout set to 60 seconds
|
|
|
69 |
return generated_ids
|
70 |
+
except concurrent.futures.TimeoutError:
|
71 |
raise TimeoutError("Text generation process timed out")
|
72 |
|
73 |
def query_and_generate_response(self, query):
|