Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,7 +21,7 @@ PUBLICATIONS_TO_RETRIEVE = 10
|
|
| 21 |
|
| 22 |
|
| 23 |
def embedding(
|
| 24 |
-
device: str = "
|
| 25 |
) -> langchain_huggingface.HuggingFaceEmbeddings:
|
| 26 |
"""Loads embedding model with specified device and normalization."""
|
| 27 |
return langchain_huggingface.HuggingFaceEmbeddings(
|
|
@@ -70,16 +70,18 @@ def preprocess(query: str, k: int) -> str:
|
|
| 70 |
|
| 71 |
|
| 72 |
@spaces.GPU
|
| 73 |
-
def reply(message: str) -> str:
|
| 74 |
"""
|
| 75 |
Generates a response to the user’s message.
|
| 76 |
"""
|
| 77 |
# Preprocess message
|
| 78 |
|
| 79 |
-
pipe = transformers.pipeline(
|
|
|
|
|
|
|
| 80 |
|
| 81 |
message = preprocess(message, PUBLICATIONS_TO_RETRIEVE)
|
| 82 |
-
return pipe(message, max_new_tokens=512
|
| 83 |
|
| 84 |
|
| 85 |
# Example Queries for Interface
|
|
|
|
| 21 |
|
| 22 |
|
| 23 |
def embedding(
|
| 24 |
+
device: str = "cuda", normalize_embeddings: bool = False
|
| 25 |
) -> langchain_huggingface.HuggingFaceEmbeddings:
|
| 26 |
"""Loads embedding model with specified device and normalization."""
|
| 27 |
return langchain_huggingface.HuggingFaceEmbeddings(
|
|
|
|
| 70 |
|
| 71 |
|
| 72 |
@spaces.GPU
|
| 73 |
+
def reply(message: str, history: list[str]) -> str:
|
| 74 |
"""
|
| 75 |
Generates a response to the user’s message.
|
| 76 |
"""
|
| 77 |
# Preprocess message
|
| 78 |
|
| 79 |
+
pipe = transformers.pipeline(
|
| 80 |
+
"text-generation", model="Qwen/Qwen2.5-7B-Instruct", device="cuda"
|
| 81 |
+
)
|
| 82 |
|
| 83 |
message = preprocess(message, PUBLICATIONS_TO_RETRIEVE)
|
| 84 |
+
return pipe(message, max_new_tokens=512)[0]["generated_text"]
|
| 85 |
|
| 86 |
|
| 87 |
# Example Queries for Interface
|