Minerva666's picture
Update app.py
1d678ac verified
import gradio as gr
import pandas as pd
# Load the dataset
df = pd.read_csv("multimodal_df.csv")
def semantic_search(query):
query = query.lower()
results = []
for _, row in df.iterrows():
score = 0
text = f"{row['Address']} {row['Location']} {row['ML_Assessment']}"
if "luxury" in query and row['predicted_Rent_category'].lower() == "high":
score += 2
elif "affordable" in query and row['predicted_Rent_category'].lower() == "low":
score += 2
if str(row['Beds']) in query:
score += 1
if any(word in text.lower() for word in query.split()):
score += 1
if score > 0:
results.append((row['Address'], row['Rent'], row['Interior_Image_URL']))
top_results = sorted(results, key=lambda x: -x[1])[:5] # Sort by rent descending
images = [f'<img src="{url}" width="300">' for _, _, url in top_results]
texts = [f"🏠 **{addr}** | πŸ’° AED {rent}" for addr, rent, _ in top_results]
display = "<br><br>".join(f"{t}<br>{i}" for t, i in zip(texts, images))
return display
# Build Gradio UI
demo = gr.Interface(
fn=semantic_search,
inputs=gr.Textbox(label="Describe what you're looking for (e.g., 'affordable 2 bed in Dubai')"),
outputs=gr.HTML(),
title="🏑 Multimodal Property Search",
description="Search for properties based on text query. Returns matching homes and photos!"
)
demo.launch()