eliasangels commited on
Commit
f1dde0e
·
verified ·
1 Parent(s): 2a07680

adding retrieval system

Browse files
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -4,9 +4,13 @@ from sentence_transformers import SentenceTransformer
4
  import torch
5
  from huggingface_hub import InferenceClient
6
 
 
 
 
 
7
 
8
- # with open("insert name here.txt", "r", encoding = "utf-8") as file:
9
- # finlitText = file.read()
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
- # cleanedChunks = preprocessText(finlitText)
33
- # chunkEmbeddings = createEmbeddings(cleanedChunks)
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
- # topResults = getTopChunks(message, chunkEmbeddings, cleanedChunks)
49
- # context = "\n\n".join(topResults)
50
 
51
- # messages.append({"role": "system",
52
- # "content": context})
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})