Spaces:
Sleeping
Sleeping
Update main.py
#5
by muaazl - opened
main.py
CHANGED
|
@@ -6,6 +6,7 @@ from sentence_transformers import SentenceTransformer
|
|
| 6 |
from thefuzz import process, fuzz
|
| 7 |
import random
|
| 8 |
import os
|
|
|
|
| 9 |
|
| 10 |
PINECONE_API_KEY = os.environ.get("PINECONE_API_KEY")
|
| 11 |
INDEX_NAME = "cine-match"
|
|
@@ -26,6 +27,11 @@ if not PINECONE_API_KEY:
|
|
| 26 |
"PINECONE_API_KEY not set. Add it to environment or ml-engine/.env"
|
| 27 |
)
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
app = FastAPI()
|
| 30 |
|
| 31 |
app.add_middleware(
|
|
@@ -53,8 +59,18 @@ class FinalRecommendationRequest(BaseModel):
|
|
| 53 |
selected_titles: list[str]
|
| 54 |
genre: str
|
| 55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
@app.post("/search")
|
| 57 |
def semantic_search(req: SearchRequest):
|
|
|
|
| 58 |
try:
|
| 59 |
query_vector = model.encode(req.query).tolist()
|
| 60 |
filter_dict = {}
|
|
@@ -127,6 +143,7 @@ def get_quiz_items(req: QuizRequest):
|
|
| 127 |
def hybrid_recommend(req: FinalRecommendationRequest):
|
| 128 |
joined_titles = ", ".join(req.selected_titles)
|
| 129 |
semantic_query = f"{req.mood} {req.genre} similar to {joined_titles}"
|
|
|
|
| 130 |
query_vector = model.encode(semantic_query).tolist()
|
| 131 |
results = index.query(vector=query_vector, top_k=60, include_metadata=True)
|
| 132 |
|
|
|
|
| 6 |
from thefuzz import process, fuzz
|
| 7 |
import random
|
| 8 |
import os
|
| 9 |
+
from supabase import create_client, Client
|
| 10 |
|
| 11 |
PINECONE_API_KEY = os.environ.get("PINECONE_API_KEY")
|
| 12 |
INDEX_NAME = "cine-match"
|
|
|
|
| 27 |
"PINECONE_API_KEY not set. Add it to environment or ml-engine/.env"
|
| 28 |
)
|
| 29 |
|
| 30 |
+
SUPABASE_URL = os.environ.get("SUPABASE_URL")
|
| 31 |
+
SUPABASE_KEY = os.environ.get("SUPABASE_KEY")
|
| 32 |
+
|
| 33 |
+
supabase: Client = create_client(SUPABASE_URL, SUPABASE_KEY)
|
| 34 |
+
|
| 35 |
app = FastAPI()
|
| 36 |
|
| 37 |
app.add_middleware(
|
|
|
|
| 59 |
selected_titles: list[str]
|
| 60 |
genre: str
|
| 61 |
|
| 62 |
+
def log_search(query_text: str, search_type: str):
|
| 63 |
+
try:
|
| 64 |
+
supabase.table("logs").insert({
|
| 65 |
+
"query": query_text,
|
| 66 |
+
"type": search_type
|
| 67 |
+
}).execute()
|
| 68 |
+
except Exception as e:
|
| 69 |
+
print(f"Error logging search: {e}")
|
| 70 |
+
|
| 71 |
@app.post("/search")
|
| 72 |
def semantic_search(req: SearchRequest):
|
| 73 |
+
log_search(req.query, "search_bar")
|
| 74 |
try:
|
| 75 |
query_vector = model.encode(req.query).tolist()
|
| 76 |
filter_dict = {}
|
|
|
|
| 143 |
def hybrid_recommend(req: FinalRecommendationRequest):
|
| 144 |
joined_titles = ", ".join(req.selected_titles)
|
| 145 |
semantic_query = f"{req.mood} {req.genre} similar to {joined_titles}"
|
| 146 |
+
log_search(semantic_query, "hybrid_wizard")
|
| 147 |
query_vector = model.encode(semantic_query).tolist()
|
| 148 |
results = index.query(vector=query_vector, top_k=60, include_metadata=True)
|
| 149 |
|