|
import os |
|
import gradio as gr |
|
from langchain.prompts import PromptTemplate |
|
from langchain.chains import LLMChain |
|
from langchain.chat_models import ChatOpenAI |
|
from models import RealEstateListing, ListingCollection |
|
from generate_listings import generate_listings |
|
from vector_store import prepare_vector_store |
|
from personalization import get_personalization_chain |
|
from config import OPENAI_API_KEY, OPENAI_API_BASE |
|
from utils import build_buyer_profile |
|
|
|
|
|
|
|
|
|
|
|
llm = ChatOpenAI( |
|
temperature = 0.4, |
|
openai_api_key = OPENAI_API_KEY, |
|
openai_api_base = OPENAI_API_BASE, |
|
|
|
) |
|
|
|
personalization_chain = get_personalization_chain(llm) |
|
|
|
|
|
|
|
|
|
df = generate_listings(llm, num_listings = 50) |
|
vectorstore = prepare_vector_store(df) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def home_match_app(location, bedrooms, bathrooms, size, amenities, extra_description): |
|
|
|
buyer_profile = build_buyer_profile(location, bedrooms, bathrooms, size, amenities, extra_description) |
|
|
|
|
|
results = vectorstore.similarity_search(buyer_profile, k=3) |
|
|
|
|
|
personalized_results = [ |
|
personalization_chain.run( |
|
buyer_profile = buyer_profile, |
|
listing_description = result.page_content |
|
) |
|
for result in results |
|
] |
|
|
|
return "\n\n---\n\n".join(personalized_results) |
|
|
|
interface = gr.Interface( |
|
fn = home_match_app, |
|
inputs = [ |
|
gr.Textbox(label = "Location" , placeholder="e.g., Munich"), |
|
gr.Number(label = "Bedrooms" , precision=0), |
|
gr.Number(label = "Bathrooms", precision=1), |
|
gr.Textbox(label = "House Size (e.g., 2000 sqft)"), |
|
gr.CheckboxGroup( |
|
choices = ["Pool", "Garage", "Solar Panels", "Smart Home"], |
|
label = "Amenities" |
|
), |
|
gr.Textbox( |
|
label = "Additional Preferences", |
|
placeholder = "e.g., Quiet neighborhood, natural lighting, eco-friendly materials, close to public transport.", |
|
lines = 6 |
|
) |
|
|
|
], |
|
outputs = "text", |
|
title = "HomeMatch: Personalized Real Estate Finder", |
|
description = "Enter your desired home features and let HomeMatch find the best listings for you." |
|
) |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
interface.launch() |
|
|