Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -27,7 +27,7 @@ def load_json_data():
|
|
27 |
data = load_json_data()
|
28 |
|
29 |
# 🔹 Initialize FAISS for Searching Relevant Answers
|
30 |
-
model = SentenceTransformer("
|
31 |
|
32 |
def create_faiss_index(data):
|
33 |
texts = list(data.values())
|
@@ -45,7 +45,7 @@ def search_faiss(query, top_k=1):
|
|
45 |
return texts[indices[0][0]] if indices[0][0] < len(texts) else "No relevant information found."
|
46 |
|
47 |
# 🔹 Hugging Face API for Additional Responses
|
48 |
-
client = InferenceClient("
|
49 |
|
50 |
def get_huggingface_response(query):
|
51 |
messages = [{"role": "system", "content": "Provide accurate food stamp information for Colorado."},
|
@@ -57,19 +57,23 @@ def get_huggingface_response(query):
|
|
57 |
|
58 |
# 🔹 Main Chatbot Function
|
59 |
def chatbot_response(message, history):
|
60 |
-
relevant_info = search_faiss(message)
|
61 |
|
62 |
if "No relevant information found." not in relevant_info:
|
63 |
-
# Summarize and clarify the retrieved policy text using Hugging Face LLM
|
64 |
user_query_with_context = f"""
|
65 |
-
The user is asking:
|
66 |
|
67 |
-
|
68 |
|
|
|
69 |
{relevant_info}
|
70 |
|
71 |
-
|
72 |
-
|
|
|
|
|
|
|
|
|
73 |
"""
|
74 |
|
75 |
return get_huggingface_response(user_query_with_context)
|
|
|
27 |
data = load_json_data()
|
28 |
|
29 |
# 🔹 Initialize FAISS for Searching Relevant Answers
|
30 |
+
model = SentenceTransformer("multi-qa-mpnet-base-dot-v1 ") # slower with great accuracy
|
31 |
|
32 |
def create_faiss_index(data):
|
33 |
texts = list(data.values())
|
|
|
45 |
return texts[indices[0][0]] if indices[0][0] < len(texts) else "No relevant information found."
|
46 |
|
47 |
# 🔹 Hugging Face API for Additional Responses
|
48 |
+
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct")
|
49 |
|
50 |
def get_huggingface_response(query):
|
51 |
messages = [{"role": "system", "content": "Provide accurate food stamp information for Colorado."},
|
|
|
57 |
|
58 |
# 🔹 Main Chatbot Function
|
59 |
def chatbot_response(message, history):
|
60 |
+
relevant_info = search_faiss(message, top_k=3) # Retrieve 3 most relevant sections
|
61 |
|
62 |
if "No relevant information found." not in relevant_info:
|
|
|
63 |
user_query_with_context = f"""
|
64 |
+
You are an expert in Colorado SNAP (food stamp) policies. The user is asking:
|
65 |
|
66 |
+
**User Question:** {message}
|
67 |
|
68 |
+
### **Relevant Policy Information Retrieved (Multiple Sources)**
|
69 |
{relevant_info}
|
70 |
|
71 |
+
### **Task:**
|
72 |
+
- **Summarize all retrieved policy information** and provide a clear, concise answer.
|
73 |
+
- **Use bullet points** for clarity.
|
74 |
+
- **If a rule applies, state it explicitly.**
|
75 |
+
- **If multiple sources provide different information, clarify the distinctions.**
|
76 |
+
- **If the policy does not fully answer the question, provide general guidance and suggest relevant keywords to search.**
|
77 |
"""
|
78 |
|
79 |
return get_huggingface_response(user_query_with_context)
|