Spaces:
Sleeping
Sleeping
adding retrieval system
Browse files
app.py
CHANGED
|
@@ -4,9 +4,13 @@ from sentence_transformers import SentenceTransformer
|
|
| 4 |
import torch
|
| 5 |
from huggingface_hub import InferenceClient
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
|
| 11 |
model = SentenceTransformer('all-MiniLM-L6-v2')
|
| 12 |
|
|
@@ -29,8 +33,8 @@ def getTopChunks(query, chunkEmbeddings, textChunks):
|
|
| 29 |
topChunks = [textChunks[i] for i in topIndices]
|
| 30 |
return topChunks
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
|
| 35 |
client = InferenceClient("deepseek-ai/DeepSeek-R1", token = os.environ.get("SF_TOKEN"))
|
| 36 |
|
|
@@ -45,11 +49,11 @@ def respond(message, history):
|
|
| 45 |
if history:
|
| 46 |
messages.extend(history)
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
|
| 54 |
messages.append({"role": "user",
|
| 55 |
"content": message})
|
|
|
|
| 4 |
import torch
|
| 5 |
from huggingface_hub import InferenceClient
|
| 6 |
|
| 7 |
+
file_names = [
|
| 8 |
+
"financial_literacy_text.txt",
|
| 9 |
+
"financial_aid_text.txt"
|
| 10 |
+
]
|
| 11 |
|
| 12 |
+
with open(file_names, "r", encoding = "utf-8") as file:
|
| 13 |
+
financialText = file.read()
|
| 14 |
|
| 15 |
model = SentenceTransformer('all-MiniLM-L6-v2')
|
| 16 |
|
|
|
|
| 33 |
topChunks = [textChunks[i] for i in topIndices]
|
| 34 |
return topChunks
|
| 35 |
|
| 36 |
+
cleanedChunks = preprocessText(financialText)
|
| 37 |
+
chunkEmbeddings = createEmbeddings(cleanedChunks)
|
| 38 |
|
| 39 |
client = InferenceClient("deepseek-ai/DeepSeek-R1", token = os.environ.get("SF_TOKEN"))
|
| 40 |
|
|
|
|
| 49 |
if history:
|
| 50 |
messages.extend(history)
|
| 51 |
|
| 52 |
+
topResults = getTopChunks(message, chunkEmbeddings, cleanedChunks)
|
| 53 |
+
context = "\n\n".join(topResults)
|
| 54 |
|
| 55 |
+
messages.append({"role": "system",
|
| 56 |
+
"content": context})
|
| 57 |
|
| 58 |
messages.append({"role": "user",
|
| 59 |
"content": message})
|