Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,8 +4,8 @@ import torch
|
|
| 4 |
import gradio as gr
|
| 5 |
from huggingface_hub import InferenceClient
|
| 6 |
|
| 7 |
-
with open("
|
| 8 |
-
|
| 9 |
|
| 10 |
def preprocess_text(text):
|
| 11 |
cleaned_text = text.strip()
|
|
@@ -17,7 +17,7 @@ def preprocess_text(text):
|
|
| 17 |
cleaned_chunks.append(chunk)
|
| 18 |
return cleaned_chunks
|
| 19 |
|
| 20 |
-
cleaned_chunks = preprocess_text(
|
| 21 |
|
| 22 |
|
| 23 |
model = SentenceTransformer('all-MiniLM-L6-v2')
|
|
@@ -44,7 +44,7 @@ client = InferenceClient("Qwen/Qwen2.5-7B-Instruct")
|
|
| 44 |
def respond(message, history):
|
| 45 |
top_chunks = get_top_chunks(message, chunk_embeddings, cleaned_chunks)
|
| 46 |
context = "\n\n".join(top_chunks)
|
| 47 |
-
messages = [{"role": "system", "content": f"
|
| 48 |
for turn in history:
|
| 49 |
if turn["role"] == "user":
|
| 50 |
messages.append({"role": "user", "content": turn["content"]})
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
from huggingface_hub import InferenceClient
|
| 6 |
|
| 7 |
+
with open("hindu_yuva_knowledge_base.txt", "r", encoding="utf-8") as file:
|
| 8 |
+
yuva_knowledge = file.read()
|
| 9 |
|
| 10 |
def preprocess_text(text):
|
| 11 |
cleaned_text = text.strip()
|
|
|
|
| 17 |
cleaned_chunks.append(chunk)
|
| 18 |
return cleaned_chunks
|
| 19 |
|
| 20 |
+
cleaned_chunks = preprocess_text(yuva_knowledge)
|
| 21 |
|
| 22 |
|
| 23 |
model = SentenceTransformer('all-MiniLM-L6-v2')
|
|
|
|
| 44 |
def respond(message, history):
|
| 45 |
top_chunks = get_top_chunks(message, chunk_embeddings, cleaned_chunks)
|
| 46 |
context = "\n\n".join(top_chunks)
|
| 47 |
+
messages = [{"role": "system", "content": f"Always greet the user first by asking 'Hello, how can I help you?'. You are an assistant answering users' questions about Hindu YUVA. You just need to pull information from the website to answer basic questions. \n{context}"}]
|
| 48 |
for turn in history:
|
| 49 |
if turn["role"] == "user":
|
| 50 |
messages.append({"role": "user", "content": turn["content"]})
|