Spaces:
Sleeping
Sleeping
Implemented a bit of the RAG (will add more tomorrow)
Browse files
app.py
CHANGED
|
@@ -3,6 +3,36 @@ from huggingface_hub import InferenceClient
|
|
| 3 |
|
| 4 |
client = InferenceClient("Qwen/Qwen2.5-7B-Instruct")
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
def respond(message, history):
|
| 7 |
messages = [
|
| 8 |
{"role": "system", "content": "You are a friendly, supportive, and mental wellness chatbot"}
|
|
|
|
| 3 |
|
| 4 |
client = InferenceClient("Qwen/Qwen2.5-7B-Instruct")
|
| 5 |
|
| 6 |
+
with open("knowledge.txt", "r", encoding="utf=8") as file:
|
| 7 |
+
knowledge_text = file.read()
|
| 8 |
+
print(knowledge_text)
|
| 9 |
+
|
| 10 |
+
def preprocess_text(text):
|
| 11 |
+
cleaned_text = text.strip()
|
| 12 |
+
|
| 13 |
+
chunks = cleaned_text.split("\n")
|
| 14 |
+
|
| 15 |
+
cleaned_chunks = []
|
| 16 |
+
|
| 17 |
+
for chunk in chunks:
|
| 18 |
+
stripped_chunk = chunk.strip()
|
| 19 |
+
if len(stripped_chunk) > 0:
|
| 20 |
+
cleaned_chunks.append(stripped_chunk)
|
| 21 |
+
print(cleaned_chunks)
|
| 22 |
+
print(len(cleaned_chunks))
|
| 23 |
+
return cleaned_chunks
|
| 24 |
+
cleaned_chunks = preprocess_text(knowledge_text)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
model = SentenceTransformer('all-MiniLM-L6-v2')
|
| 28 |
+
|
| 29 |
+
def create_embeddings(text_chunks):
|
| 30 |
+
chunk_embeddings = model.encode(text_chunks, convert_to_tensor=True)
|
| 31 |
+
print(chunk_embeddings)
|
| 32 |
+
print(chunk_embeddings.shape)
|
| 33 |
+
return chunk_embeddings
|
| 34 |
+
chunk_embeddings = create_embeddings(cleaned_chunks)
|
| 35 |
+
|
| 36 |
def respond(message, history):
|
| 37 |
messages = [
|
| 38 |
{"role": "system", "content": "You are a friendly, supportive, and mental wellness chatbot"}
|