Minerva666 commited on
Commit
1d678ac
Β·
verified Β·
1 Parent(s): 138bed5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -43
app.py CHANGED
@@ -1,67 +1,47 @@
1
  import gradio as gr
2
  import pandas as pd
3
 
4
- # Load your multimodal dataset
5
  df = pd.read_csv("multimodal_df.csv")
6
 
7
- # Optional: fill NAs for consistency
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
- combined_text = f"{row['Address']} {row['Location']} {row['ML_Assessment']} {row['predicted_Rent_category']}".lower()
 
 
 
 
 
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
- if any(word in combined_text for word in query.split()):
 
26
  score += 1
27
 
28
  if score > 0:
29
- results.append((score, row))
30
 
31
- # Sort by score
32
- results.sort(key=lambda x: x[0], reverse=True)
33
- top_results = results[:top_k]
34
 
35
- # Prepare output
36
- outputs = []
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
- return outputs
48
 
49
- # Gradio UI
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=search_interface,
60
- inputs=gr.Textbox(placeholder="e.g. affordable 2 bedroom in Business Bay", label="Enter your property search query"),
61
- outputs=gr.Group(),
62
- title="🏑 Semantic Real Estate Search (Multimodal)",
63
- description="Search Abu Dhabi & Dubai listings using smart natural language queries. Powered by ML, images & embeddings."
64
  )
65
 
66
- if __name__ == "__main__":
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()