Spaces:
Paused
Paused
Carlos Rosas
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -46,8 +46,8 @@ table = db.open_table("edunat19")
|
|
46 |
def hybrid_search(text):
|
47 |
results = table.search(text, query_type="hybrid").limit(5).to_pandas()
|
48 |
|
49 |
-
#
|
50 |
-
seen_hashes =
|
51 |
|
52 |
document = []
|
53 |
document_html = []
|
@@ -58,24 +58,22 @@ def hybrid_search(text):
|
|
58 |
if hash_id in seen_hashes:
|
59 |
continue
|
60 |
|
61 |
-
seen_hashes.
|
62 |
title = row['section']
|
63 |
content = row['text']
|
64 |
|
65 |
source_text = f"<|source_start|><|source_id_start|>{hash_id}<|source_id_end|>{title}\n{content}<|source_end|>"
|
66 |
document.append(source_text)
|
67 |
document_html.append(f'<div class="source" id="{hash_id}"><p><b>{hash_id}</b> : {title}<br>{content}</div>')
|
68 |
-
|
69 |
-
#
|
70 |
-
print(f"
|
71 |
-
print(f"Length of source text: {len(source_text)}")
|
72 |
|
73 |
document = "\n".join(document)
|
74 |
document_html = '<div id="source_listing">' + "".join(document_html) + "</div>"
|
75 |
|
76 |
-
#
|
77 |
-
print(f"Total
|
78 |
-
|
79 |
return document, document_html
|
80 |
|
81 |
class pleiasBot:
|
@@ -86,9 +84,13 @@ class pleiasBot:
|
|
86 |
fiches, fiches_html = hybrid_search(user_message)
|
87 |
|
88 |
detailed_prompt = f"""<|query_start|>{user_message}<|query_end|>\n{fiches}\n<|source_analysis_start|>"""
|
89 |
-
|
|
|
|
|
|
|
90 |
# Convert inputs to tensor
|
91 |
input_ids = tokenizer.encode(detailed_prompt, return_tensors="pt").to(device)
|
|
|
92 |
attention_mask = torch.ones_like(input_ids)
|
93 |
|
94 |
try:
|
|
|
46 |
def hybrid_search(text):
|
47 |
results = table.search(text, query_type="hybrid").limit(5).to_pandas()
|
48 |
|
49 |
+
# Add a check for duplicate hashes
|
50 |
+
seen_hashes = set()
|
51 |
|
52 |
document = []
|
53 |
document_html = []
|
|
|
58 |
if hash_id in seen_hashes:
|
59 |
continue
|
60 |
|
61 |
+
seen_hashes.add(hash_id)
|
62 |
title = row['section']
|
63 |
content = row['text']
|
64 |
|
65 |
source_text = f"<|source_start|><|source_id_start|>{hash_id}<|source_id_end|>{title}\n{content}<|source_end|>"
|
66 |
document.append(source_text)
|
67 |
document_html.append(f'<div class="source" id="{hash_id}"><p><b>{hash_id}</b> : {title}<br>{content}</div>')
|
68 |
+
|
69 |
+
# Add debug print
|
70 |
+
print(f"Source added: {hash_id}")
|
|
|
71 |
|
72 |
document = "\n".join(document)
|
73 |
document_html = '<div id="source_listing">' + "".join(document_html) + "</div>"
|
74 |
|
75 |
+
# Add debug print
|
76 |
+
print(f"Total sources: {len(seen_hashes)}")
|
|
|
77 |
return document, document_html
|
78 |
|
79 |
class pleiasBot:
|
|
|
84 |
fiches, fiches_html = hybrid_search(user_message)
|
85 |
|
86 |
detailed_prompt = f"""<|query_start|>{user_message}<|query_end|>\n{fiches}\n<|source_analysis_start|>"""
|
87 |
+
|
88 |
+
# Add debug print
|
89 |
+
print("Model input length:", len(detailed_prompt))
|
90 |
+
|
91 |
# Convert inputs to tensor
|
92 |
input_ids = tokenizer.encode(detailed_prompt, return_tensors="pt").to(device)
|
93 |
+
print("Token count:", len(input_ids[0]))
|
94 |
attention_mask = torch.ones_like(input_ids)
|
95 |
|
96 |
try:
|