Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,67 +1,47 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
|
| 4 |
-
# Load
|
| 5 |
df = pd.read_csv("multimodal_df.csv")
|
| 6 |
|
| 7 |
-
|
| 8 |
-
df.fillna('', inplace=True)
|
| 9 |
-
|
| 10 |
-
# Basic semantic scoring (tunable)
|
| 11 |
-
def semantic_search(query, top_k=5):
|
| 12 |
query = query.lower()
|
| 13 |
results = []
|
| 14 |
|
| 15 |
for _, row in df.iterrows():
|
| 16 |
score = 0
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
if 'affordable' in query or 'cheap' in query:
|
| 20 |
-
score += 2 if row['Rent'] < 40000 else 0
|
| 21 |
-
if 'luxury' in query or 'premium' in query:
|
| 22 |
-
score += 2 if row['Rent'] > 100000 else 0
|
| 23 |
if str(row['Beds']) in query:
|
| 24 |
score += 1
|
| 25 |
-
|
|
|
|
| 26 |
score += 1
|
| 27 |
|
| 28 |
if score > 0:
|
| 29 |
-
results.append((
|
| 30 |
|
| 31 |
-
# Sort by
|
| 32 |
-
results.sort(key=lambda x: x[0], reverse=True)
|
| 33 |
-
top_results = results[:top_k]
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
for score, row in top_results:
|
| 38 |
-
info = f"π **{row['Address']}**\n"
|
| 39 |
-
info += f"π Location: {row['Location']}\n"
|
| 40 |
-
info += f"π° Rent: AED {int(row['Rent']):,}\n"
|
| 41 |
-
info += f"ποΈ Beds: {int(row['Beds'])}\n"
|
| 42 |
-
info += f"π§ ML Assessment: {row['ML_Assessment']}\n"
|
| 43 |
-
info += f"π Predicted Category: {row['predicted_Rent_category']}\n"
|
| 44 |
-
image_url = row['Interior_Image_URL']
|
| 45 |
-
outputs.append((info, image_url))
|
| 46 |
|
| 47 |
-
|
| 48 |
|
| 49 |
-
|
| 50 |
-
def search_interface(query):
|
| 51 |
-
results = semantic_search(query)
|
| 52 |
-
cards = []
|
| 53 |
-
for info, image_url in results:
|
| 54 |
-
cards.append(gr.HTML(info))
|
| 55 |
-
cards.append(gr.Image(value=image_url, label="Interior View"))
|
| 56 |
-
return cards
|
| 57 |
|
|
|
|
| 58 |
demo = gr.Interface(
|
| 59 |
-
fn=
|
| 60 |
-
inputs=gr.Textbox(
|
| 61 |
-
outputs=gr.
|
| 62 |
-
title="π‘
|
| 63 |
-
description="Search
|
| 64 |
)
|
| 65 |
|
| 66 |
-
|
| 67 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
|
| 4 |
+
# Load the dataset
|
| 5 |
df = pd.read_csv("multimodal_df.csv")
|
| 6 |
|
| 7 |
+
def semantic_search(query):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
query = query.lower()
|
| 9 |
results = []
|
| 10 |
|
| 11 |
for _, row in df.iterrows():
|
| 12 |
score = 0
|
| 13 |
+
text = f"{row['Address']} {row['Location']} {row['ML_Assessment']}"
|
| 14 |
+
|
| 15 |
+
if "luxury" in query and row['predicted_Rent_category'].lower() == "high":
|
| 16 |
+
score += 2
|
| 17 |
+
elif "affordable" in query and row['predicted_Rent_category'].lower() == "low":
|
| 18 |
+
score += 2
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
if str(row['Beds']) in query:
|
| 21 |
score += 1
|
| 22 |
+
|
| 23 |
+
if any(word in text.lower() for word in query.split()):
|
| 24 |
score += 1
|
| 25 |
|
| 26 |
if score > 0:
|
| 27 |
+
results.append((row['Address'], row['Rent'], row['Interior_Image_URL']))
|
| 28 |
|
| 29 |
+
top_results = sorted(results, key=lambda x: -x[1])[:5] # Sort by rent descending
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
images = [f'<img src="{url}" width="300">' for _, _, url in top_results]
|
| 32 |
+
texts = [f"π **{addr}** | π° AED {rent}" for addr, rent, _ in top_results]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
display = "<br><br>".join(f"{t}<br>{i}" for t, i in zip(texts, images))
|
| 35 |
|
| 36 |
+
return display
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
+
# Build Gradio UI
|
| 39 |
demo = gr.Interface(
|
| 40 |
+
fn=semantic_search,
|
| 41 |
+
inputs=gr.Textbox(label="Describe what you're looking for (e.g., 'affordable 2 bed in Dubai')"),
|
| 42 |
+
outputs=gr.HTML(),
|
| 43 |
+
title="π‘ Multimodal Property Search",
|
| 44 |
+
description="Search for properties based on text query. Returns matching homes and photos!"
|
| 45 |
)
|
| 46 |
|
| 47 |
+
demo.launch()
|
|
|