Spaces:
Runtime error
Runtime error
update
Browse files
app.py
CHANGED
|
@@ -6,7 +6,7 @@ client = InferenceClient("Qwen/Qwen2.5-7B-Instruct")
|
|
| 6 |
|
| 7 |
with open("knowledge.txt", "r", encoding="utf-8") as file:
|
| 8 |
knowledge_text = file.read()
|
| 9 |
-
print(knowledge_text)
|
| 10 |
|
| 11 |
def preprocess_text(text):
|
| 12 |
cleaned_text = text.strip()
|
|
@@ -19,8 +19,8 @@ def preprocess_text(text):
|
|
| 19 |
stripped_chunk = chunk.strip()
|
| 20 |
if len(stripped_chunk) > 0:
|
| 21 |
cleaned_chunks.append(stripped_chunk)
|
| 22 |
-
print(cleaned_chunks)
|
| 23 |
-
print(len(cleaned_chunks))
|
| 24 |
return cleaned_chunks
|
| 25 |
cleaned_chunks = preprocess_text(knowledge_text)
|
| 26 |
|
|
@@ -29,8 +29,8 @@ model = SentenceTransformer('all-MiniLM-L6-v2')
|
|
| 29 |
|
| 30 |
def create_embeddings(text_chunks):
|
| 31 |
chunk_embeddings = model.encode(text_chunks, convert_to_tensor=True)
|
| 32 |
-
print(chunk_embeddings)
|
| 33 |
-
print(chunk_embeddings.shape)
|
| 34 |
return chunk_embeddings
|
| 35 |
chunk_embeddings = create_embeddings(cleaned_chunks)
|
| 36 |
|
|
@@ -71,7 +71,7 @@ def respond(message, history):
|
|
| 71 |
return "I'm mainly here to support teen mental wellness. Try asking me about stress, anxiety, school pressure, friendships, emotions, sleep, or coping strategies."
|
| 72 |
|
| 73 |
relevant_chunk = get_top_chunk(message)
|
| 74 |
-
print("Retrieved chunk:", relevant_chunk) # we are using this line to test RAG system (the terminal will
|
| 75 |
|
| 76 |
messages = [
|
| 77 |
{
|
|
@@ -110,12 +110,14 @@ User question:
|
|
| 110 |
chatbot = gr.ChatInterface(
|
| 111 |
respond,
|
| 112 |
title="Teen Mental Wellness Chatbot",
|
|
|
|
| 113 |
examples=[ # give the user example prompts
|
| 114 |
"I've been feeling stressed about school lately.",
|
| 115 |
"What are some coping strategies for anxiety?",
|
| 116 |
"How can I manage test anxiety?",
|
| 117 |
"What should I do when I'm feeling overwhelmed?"
|
| 118 |
-
]
|
|
|
|
| 119 |
|
| 120 |
)
|
| 121 |
chatbot.launch()
|
|
|
|
| 6 |
|
| 7 |
with open("knowledge.txt", "r", encoding="utf-8") as file:
|
| 8 |
knowledge_text = file.read()
|
| 9 |
+
# print(knowledge_text)
|
| 10 |
|
| 11 |
def preprocess_text(text):
|
| 12 |
cleaned_text = text.strip()
|
|
|
|
| 19 |
stripped_chunk = chunk.strip()
|
| 20 |
if len(stripped_chunk) > 0:
|
| 21 |
cleaned_chunks.append(stripped_chunk)
|
| 22 |
+
# print(cleaned_chunks)
|
| 23 |
+
# print(len(cleaned_chunks))
|
| 24 |
return cleaned_chunks
|
| 25 |
cleaned_chunks = preprocess_text(knowledge_text)
|
| 26 |
|
|
|
|
| 29 |
|
| 30 |
def create_embeddings(text_chunks):
|
| 31 |
chunk_embeddings = model.encode(text_chunks, convert_to_tensor=True)
|
| 32 |
+
# print(chunk_embeddings)
|
| 33 |
+
# print(chunk_embeddings.shape)
|
| 34 |
return chunk_embeddings
|
| 35 |
chunk_embeddings = create_embeddings(cleaned_chunks)
|
| 36 |
|
|
|
|
| 71 |
return "I'm mainly here to support teen mental wellness. Try asking me about stress, anxiety, school pressure, friendships, emotions, sleep, or coping strategies."
|
| 72 |
|
| 73 |
relevant_chunk = get_top_chunk(message)
|
| 74 |
+
print("Retrieved chunk:", relevant_chunk) # we are using this line to test RAG system (the terminal will show what knowledge chunk chatbot used)
|
| 75 |
|
| 76 |
messages = [
|
| 77 |
{
|
|
|
|
| 110 |
chatbot = gr.ChatInterface(
|
| 111 |
respond,
|
| 112 |
title="Teen Mental Wellness Chatbot",
|
| 113 |
+
description="A supportive chatbot that uses mental wellness resources to suggest coping strategies for teens. It is not a replacement for professional help.",
|
| 114 |
examples=[ # give the user example prompts
|
| 115 |
"I've been feeling stressed about school lately.",
|
| 116 |
"What are some coping strategies for anxiety?",
|
| 117 |
"How can I manage test anxiety?",
|
| 118 |
"What should I do when I'm feeling overwhelmed?"
|
| 119 |
+
],
|
| 120 |
+
theme=gr.themes.Soft()
|
| 121 |
|
| 122 |
)
|
| 123 |
chatbot.launch()
|