Update app.py
Browse files
app.py
CHANGED
@@ -11,6 +11,7 @@ from langchain.text_splitter import RecursiveCharacterTextSplitter
|
|
11 |
from langchain_community.vectorstores import FAISS
|
12 |
from langchain.schema import Document
|
13 |
from langchain.embeddings import HuggingFaceEmbeddings
|
|
|
14 |
|
15 |
# Create the Vision 2030 Assistant class
|
16 |
class Vision2030Assistant:
|
@@ -86,6 +87,7 @@ def retrieve_context(query, vector_store, top_k=5):
|
|
86 |
|
87 |
return contexts
|
88 |
|
|
|
89 |
def generate_response(query, contexts, model, tokenizer, language="auto"):
|
90 |
"""Generate a response using retrieved contexts with ALLaM-specific formatting"""
|
91 |
# Auto-detect language if not specified
|
@@ -221,6 +223,7 @@ tokenizer = None
|
|
221 |
assistant = None
|
222 |
|
223 |
# Load the model and tokenizer
|
|
|
224 |
def load_model_and_tokenizer():
|
225 |
global model, tokenizer
|
226 |
|
@@ -294,6 +297,7 @@ def process_pdfs(pdf_files):
|
|
294 |
|
295 |
return f"Successfully processed {len(documents)} documents. The assistant is ready to use!"
|
296 |
|
|
|
297 |
def answer_query(message, history):
|
298 |
global assistant
|
299 |
|
|
|
11 |
from langchain_community.vectorstores import FAISS
|
12 |
from langchain.schema import Document
|
13 |
from langchain.embeddings import HuggingFaceEmbeddings
|
14 |
+
import spaces # Add this import for Hugging Face Spaces
|
15 |
|
16 |
# Create the Vision 2030 Assistant class
|
17 |
class Vision2030Assistant:
|
|
|
87 |
|
88 |
return contexts
|
89 |
|
90 |
+
@spaces.GPU # Add decorator for GPU usage
|
91 |
def generate_response(query, contexts, model, tokenizer, language="auto"):
|
92 |
"""Generate a response using retrieved contexts with ALLaM-specific formatting"""
|
93 |
# Auto-detect language if not specified
|
|
|
223 |
assistant = None
|
224 |
|
225 |
# Load the model and tokenizer
|
226 |
+
@spaces.GPU # Add decorator for GPU usage
|
227 |
def load_model_and_tokenizer():
|
228 |
global model, tokenizer
|
229 |
|
|
|
297 |
|
298 |
return f"Successfully processed {len(documents)} documents. The assistant is ready to use!"
|
299 |
|
300 |
+
@spaces.GPU # Add decorator for GPU usage
|
301 |
def answer_query(message, history):
|
302 |
global assistant
|
303 |
|