Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -6,7 +6,7 @@ from pydantic import BaseModel, Field
|
|
| 6 |
from typing import List
|
| 7 |
import firebase_admin
|
| 8 |
from firebase_admin import credentials, firestore
|
| 9 |
-
|
| 10 |
# --- Local Imports ---
|
| 11 |
from encoder import SentenceEncoder
|
| 12 |
from populate_chroma import populate_vector_db # For the setup endpoint
|
|
@@ -165,19 +165,18 @@ def get_profile_recommendations(profile: UserProfile, db_client: firestore.Clien
|
|
| 165 |
query_text = f"Skills: {', '.join(profile.skills)}. Sectors: {', '.join(profile.sectors)}"
|
| 166 |
query_embedding = encoder.encode([query_text])[0].tolist()
|
| 167 |
|
| 168 |
-
results = chroma_collection.query(query_embeddings=[query_embedding], n_results=3)
|
| 169 |
|
| 170 |
recommendations = []
|
| 171 |
ids = results.get('ids', [[]])[0]
|
| 172 |
distances = results.get('distances', [[]])[0]
|
| 173 |
-
|
| 174 |
for i, internship_id in enumerate(ids):
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
return {"recommendations": recommendations}
|
| 182 |
|
| 183 |
@app.post("/search", response_model=RecommendationResponse)
|
|
@@ -187,19 +186,13 @@ def search_internships(search: SearchQuery, db_client: firestore.Client = Depend
|
|
| 187 |
|
| 188 |
query_embedding = encoder.encode([search.query])[0].tolist()
|
| 189 |
|
| 190 |
-
results = chroma_collection.query(query_embeddings=[query_embedding], n_results=3)
|
| 191 |
|
| 192 |
recommendations = []
|
| 193 |
ids = results.get('ids', [[]])[0]
|
| 194 |
distances = results.get('distances', [[]])[0]
|
| 195 |
-
|
| 196 |
for i, internship_id in enumerate(ids):
|
| 197 |
-
|
| 198 |
-
if doc_ref.exists:
|
| 199 |
-
internship_data = doc_ref.to_dict()
|
| 200 |
-
internship_data['score'] = 1 - distances[i]
|
| 201 |
-
recommendations.append(internship_data)
|
| 202 |
-
|
| 203 |
return {"recommendations": recommendations}
|
| 204 |
|
| 205 |
@app.post("/chat", response_model=ChatResponse)
|
|
|
|
| 6 |
from typing import List
|
| 7 |
import firebase_admin
|
| 8 |
from firebase_admin import credentials, firestore
|
| 9 |
+
import random
|
| 10 |
# --- Local Imports ---
|
| 11 |
from encoder import SentenceEncoder
|
| 12 |
from populate_chroma import populate_vector_db # For the setup endpoint
|
|
|
|
| 165 |
query_text = f"Skills: {', '.join(profile.skills)}. Sectors: {', '.join(profile.sectors)}"
|
| 166 |
query_embedding = encoder.encode([query_text])[0].tolist()
|
| 167 |
|
| 168 |
+
results = chroma_collection.query(query_embeddings=[query_embedding], n_results=random.randint(3, 5))
|
| 169 |
|
| 170 |
recommendations = []
|
| 171 |
ids = results.get('ids', [[]])[0]
|
| 172 |
distances = results.get('distances', [[]])[0]
|
| 173 |
+
|
| 174 |
for i, internship_id in enumerate(ids):
|
| 175 |
+
recommendations.append({
|
| 176 |
+
"internship_id": internship_id,
|
| 177 |
+
"score": 1 - distances[i]
|
| 178 |
+
})
|
| 179 |
+
|
|
|
|
| 180 |
return {"recommendations": recommendations}
|
| 181 |
|
| 182 |
@app.post("/search", response_model=RecommendationResponse)
|
|
|
|
| 186 |
|
| 187 |
query_embedding = encoder.encode([search.query])[0].tolist()
|
| 188 |
|
| 189 |
+
results = chroma_collection.query(query_embeddings=[query_embedding], n_results=random.randint(3, 5))
|
| 190 |
|
| 191 |
recommendations = []
|
| 192 |
ids = results.get('ids', [[]])[0]
|
| 193 |
distances = results.get('distances', [[]])[0]
|
|
|
|
| 194 |
for i, internship_id in enumerate(ids):
|
| 195 |
+
recommendations.append({"internship_id": internship_id, "score": 1 - distances[i]})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
return {"recommendations": recommendations}
|
| 197 |
|
| 198 |
@app.post("/chat", response_model=ChatResponse)
|