CoolFace
Apppublic

Hasnain-Ali/Real_Estate_Recomendation_System

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
main.py34 linesDownload Raw Back to root
1from fastapi import FastAPI2from pydantic import BaseModel3from sentence_transformers import SentenceTransformer4import faiss5 6app = FastAPI()7 8properties = []9ids = []10model = SentenceTransformer('sentence-transformers/all-MiniLM-L12-v2')11dim = 38412index = faiss.IndexFlatL2(dim)13 14class Property(BaseModel):15    id: str16    text: str17 18class Query(BaseModel):19    text: str20 21@app.post("/add_property")22def add_property(prop: Property):23    embedding = model.encode([prop.text])24    index.add(embedding)25    ids.append(prop.id)26    properties.append(prop.text)27    return {"message": "Property added", "id": prop.id}28 29@app.post("/recommend")30def recommend(query: Query):31    query_embedding = model.encode([query.text])32    D, I = index.search(query_embedding, k=5)33    recommendations = [ids[i] for i in I[0]]34    return {"recommended_ids": recommendations}