Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,7 @@ import json
|
|
| 4 |
import os
|
| 5 |
import re
|
| 6 |
import requests
|
| 7 |
-
from memory_store import log_chat, build_or_update_index, LOG_FILE
|
| 8 |
|
| 9 |
GOOGLE_API_KEY = "AIzaSyCgOaCQEVvOuNtZhOkrmcnqzuiiPDA6b1Q" # π Replace this
|
| 10 |
SEARCH_ENGINE_ID = "17357d675fc704764" # π Replace this
|
|
@@ -17,9 +17,11 @@ if os.path.exists(COURSE_DB_PATH):
|
|
| 17 |
else:
|
| 18 |
linkedin_courses = []
|
| 19 |
|
| 20 |
-
# === Free-form Chat Function ===
|
| 21 |
def chat_with_user(message, history):
|
| 22 |
-
|
|
|
|
|
|
|
| 23 |
log_chat(message, answer)
|
| 24 |
return history + [(message, answer)], ""
|
| 25 |
|
|
@@ -81,7 +83,7 @@ def course_agent(profession, query):
|
|
| 81 |
|
| 82 |
# === Combined UI ===
|
| 83 |
with gr.Blocks(title="π§ AI Course Finder with Memory") as demo:
|
| 84 |
-
gr.Markdown("## π Smart Agent with FAISS + Logging")
|
| 85 |
|
| 86 |
with gr.Tab("π Course Finder"):
|
| 87 |
with gr.Row():
|
|
|
|
| 4 |
import os
|
| 5 |
import re
|
| 6 |
import requests
|
| 7 |
+
from memory_store import log_chat, build_or_update_index, LOG_FILE, search_similar
|
| 8 |
|
| 9 |
GOOGLE_API_KEY = "AIzaSyCgOaCQEVvOuNtZhOkrmcnqzuiiPDA6b1Q" # π Replace this
|
| 10 |
SEARCH_ENGINE_ID = "17357d675fc704764" # π Replace this
|
|
|
|
| 17 |
else:
|
| 18 |
linkedin_courses = []
|
| 19 |
|
| 20 |
+
# === Free-form Chat Function (RAG-based) ===
|
| 21 |
def chat_with_user(message, history):
|
| 22 |
+
retrieved = search_similar(message)
|
| 23 |
+
context = "\n".join([f"β’ {r}" for r in retrieved]) if retrieved else "(no relevant context found)"
|
| 24 |
+
answer = f"Based on your query, here's what I found:\n{context}"
|
| 25 |
log_chat(message, answer)
|
| 26 |
return history + [(message, answer)], ""
|
| 27 |
|
|
|
|
| 83 |
|
| 84 |
# === Combined UI ===
|
| 85 |
with gr.Blocks(title="π§ AI Course Finder with Memory") as demo:
|
| 86 |
+
gr.Markdown("## π Smart Agent with FAISS + Logging + RAG")
|
| 87 |
|
| 88 |
with gr.Tab("π Course Finder"):
|
| 89 |
with gr.Row():
|