Spaces:
Sleeping
Sleeping
Upload 5 files
Browse files- .gitattributes +2 -0
- README.md +43 -6
- airbnb_recommendation_output.csv +3 -0
- app.py +373 -0
- requirements.txt +5 -0
- synthetic_airbnb_project_data.csv +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
airbnb_recommendation_output.csv filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
synthetic_airbnb_project_data.csv filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -1,12 +1,49 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
---
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: AI Rental Performance Assistant
|
| 3 |
+
emoji: ๐ก
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: indigo
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.44.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# AI Rental Performance Assistant
|
| 13 |
+
|
| 14 |
+
This Hugging Face Space runs an end-to-end short-term rental pricing and performance pipeline.
|
| 15 |
+
|
| 16 |
+
## What the app does
|
| 17 |
+
|
| 18 |
+
1. Loads the Airbnb project datasets.
|
| 19 |
+
2. Lets the user input a rental listing scenario.
|
| 20 |
+
3. Finds comparable listings by neighbourhood group, neighbourhood, and room type.
|
| 21 |
+
4. Calculates competitor price, price gap, estimated occupancy, revenue, demand score, and opportunity score.
|
| 22 |
+
5. Produces a pricing recommendation.
|
| 23 |
+
6. Sends the pipeline output to an n8n webhook.
|
| 24 |
+
7. Displays the n8n response as an automation output.
|
| 25 |
+
|
| 26 |
+
## n8n integration
|
| 27 |
+
|
| 28 |
+
The app supports two ways to configure n8n:
|
| 29 |
+
|
| 30 |
+
- Add your webhook URL directly in the app input field.
|
| 31 |
+
- Or set a Hugging Face Space secret named `N8N_WEBHOOK_URL`.
|
| 32 |
+
|
| 33 |
+
Expected n8n response format:
|
| 34 |
+
|
| 35 |
+
```json
|
| 36 |
+
{
|
| 37 |
+
"status": "success",
|
| 38 |
+
"insight": "This listing has high demand potential but is underpriced.",
|
| 39 |
+
"next_step": "Consider increasing price by 8% and improving review quality.",
|
| 40 |
+
"log": "Saved to database and flagged for monitoring"
|
| 41 |
+
}
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
## Files
|
| 45 |
+
|
| 46 |
+
- `app.py`: main Gradio app
|
| 47 |
+
- `requirements.txt`: Python dependencies
|
| 48 |
+
- `synthetic_airbnb_project_data.csv`: full project dataset
|
| 49 |
+
- `airbnb_recommendation_output.csv`: recommendation output dataset
|
airbnb_recommendation_output.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import json
|
| 3 |
+
from datetime import datetime
|
| 4 |
+
from typing import Dict, Tuple
|
| 5 |
+
|
| 6 |
+
import numpy as np
|
| 7 |
+
import pandas as pd
|
| 8 |
+
import plotly.express as px
|
| 9 |
+
import requests
|
| 10 |
+
import gradio as gr
|
| 11 |
+
|
| 12 |
+
DATA_FULL = "synthetic_airbnb_project_data.csv"
|
| 13 |
+
DATA_RECO = "airbnb_recommendation_output.csv"
|
| 14 |
+
|
| 15 |
+
# -----------------------------
|
| 16 |
+
# Data loading
|
| 17 |
+
# -----------------------------
|
| 18 |
+
|
| 19 |
+
@gr.cache()
|
| 20 |
+
def load_data() -> Tuple[pd.DataFrame, pd.DataFrame]:
|
| 21 |
+
full = pd.read_csv(DATA_FULL)
|
| 22 |
+
reco = pd.read_csv(DATA_RECO)
|
| 23 |
+
|
| 24 |
+
# Defensive cleaning
|
| 25 |
+
for df in (full, reco):
|
| 26 |
+
if "price" in df.columns:
|
| 27 |
+
df["price"] = pd.to_numeric(df["price"], errors="coerce")
|
| 28 |
+
if "occupancy_rate" in df.columns:
|
| 29 |
+
df["occupancy_rate"] = pd.to_numeric(df["occupancy_rate"], errors="coerce")
|
| 30 |
+
if "monthly_revenue" in df.columns:
|
| 31 |
+
df["monthly_revenue"] = pd.to_numeric(df["monthly_revenue"], errors="coerce")
|
| 32 |
+
if "demand_score" in df.columns:
|
| 33 |
+
df["demand_score"] = pd.to_numeric(df["demand_score"], errors="coerce")
|
| 34 |
+
if "customer_sentiment_score" in df.columns:
|
| 35 |
+
df["customer_sentiment_score"] = pd.to_numeric(df["customer_sentiment_score"], errors="coerce")
|
| 36 |
+
if "synthetic_rating" in df.columns:
|
| 37 |
+
df["synthetic_rating"] = pd.to_numeric(df["synthetic_rating"], errors="coerce")
|
| 38 |
+
|
| 39 |
+
full = full.dropna(subset=["price", "neighbourhood_group", "room_type"])
|
| 40 |
+
reco = reco.dropna(subset=["price", "neighbourhood_group", "room_type"])
|
| 41 |
+
return full, reco
|
| 42 |
+
|
| 43 |
+
full_df, reco_df = load_data()
|
| 44 |
+
|
| 45 |
+
NEIGH_GROUPS = sorted(full_df["neighbourhood_group"].dropna().unique().tolist())
|
| 46 |
+
ROOM_TYPES = sorted(full_df["room_type"].dropna().unique().tolist())
|
| 47 |
+
SEASONS = sorted(full_df["season"].dropna().unique().tolist()) if "season" in full_df.columns else ["Spring", "Summer", "Autumn", "Winter"]
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def neighbourhood_choices(group: str):
|
| 51 |
+
if not group:
|
| 52 |
+
return gr.Dropdown(choices=[], value=None)
|
| 53 |
+
vals = sorted(full_df.loc[full_df["neighbourhood_group"] == group, "neighbourhood"].dropna().unique().tolist())
|
| 54 |
+
return gr.Dropdown(choices=vals, value=vals[0] if vals else None)
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
# -----------------------------
|
| 58 |
+
# Pipeline logic
|
| 59 |
+
# -----------------------------
|
| 60 |
+
|
| 61 |
+
def safe_mean(series, default=0):
|
| 62 |
+
val = pd.to_numeric(series, errors="coerce").mean()
|
| 63 |
+
if pd.isna(val):
|
| 64 |
+
return default
|
| 65 |
+
return float(val)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def get_comparables(group: str, neighbourhood: str, room_type: str, price: float) -> pd.DataFrame:
|
| 69 |
+
# 1) Most precise: same neighbourhood + room type
|
| 70 |
+
comps = full_df[(full_df["neighbourhood_group"] == group) &
|
| 71 |
+
(full_df["neighbourhood"] == neighbourhood) &
|
| 72 |
+
(full_df["room_type"] == room_type)].copy()
|
| 73 |
+
|
| 74 |
+
# 2) Fallback: same group + room type
|
| 75 |
+
if len(comps) < 10:
|
| 76 |
+
comps = full_df[(full_df["neighbourhood_group"] == group) &
|
| 77 |
+
(full_df["room_type"] == room_type)].copy()
|
| 78 |
+
|
| 79 |
+
# 3) Fallback: same room type globally
|
| 80 |
+
if len(comps) < 10:
|
| 81 |
+
comps = full_df[full_df["room_type"] == room_type].copy()
|
| 82 |
+
|
| 83 |
+
# 4) Prefer listings in a reasonable price band, but only if it does not remove too much data
|
| 84 |
+
if price and price > 0 and len(comps) > 30:
|
| 85 |
+
band = comps[(comps["price"] >= price * 0.5) & (comps["price"] <= price * 1.5)]
|
| 86 |
+
if len(band) >= 10:
|
| 87 |
+
comps = band
|
| 88 |
+
|
| 89 |
+
return comps
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
def demand_level_from_score(score: float) -> str:
|
| 93 |
+
if score >= 70:
|
| 94 |
+
return "High"
|
| 95 |
+
if score >= 45:
|
| 96 |
+
return "Medium"
|
| 97 |
+
return "Low"
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def build_recommendation(price, competitor_avg, occupancy, demand_score, sentiment, rating):
|
| 101 |
+
price_gap_pct = ((price - competitor_avg) / competitor_avg * 100) if competitor_avg else 0
|
| 102 |
+
|
| 103 |
+
if price_gap_pct > 18 and demand_score < 65:
|
| 104 |
+
pricing_action = "Consider lowering price"
|
| 105 |
+
suggested_price = round(competitor_avg * 1.05, 0)
|
| 106 |
+
elif price_gap_pct < -12 and demand_score >= 60 and occupancy >= 0.60:
|
| 107 |
+
pricing_action = "Consider raising price"
|
| 108 |
+
suggested_price = round(min(competitor_avg * 0.98, price * 1.12), 0)
|
| 109 |
+
else:
|
| 110 |
+
pricing_action = "Keep price stable"
|
| 111 |
+
suggested_price = round(price, 0)
|
| 112 |
+
|
| 113 |
+
actions = []
|
| 114 |
+
if pricing_action == "Consider lowering price":
|
| 115 |
+
actions.append("Lower price slightly to recover competitiveness")
|
| 116 |
+
elif pricing_action == "Consider raising price":
|
| 117 |
+
actions.append("Raise price carefully because demand is strong")
|
| 118 |
+
else:
|
| 119 |
+
actions.append("Keep price stable and monitor demand")
|
| 120 |
+
|
| 121 |
+
if occupancy < 0.45:
|
| 122 |
+
actions.append("Boost visibility or add promotions")
|
| 123 |
+
elif occupancy > 0.70:
|
| 124 |
+
actions.append("Strong occupancy: test premium pricing")
|
| 125 |
+
else:
|
| 126 |
+
actions.append("Demand is stable")
|
| 127 |
+
|
| 128 |
+
if sentiment < 0:
|
| 129 |
+
actions.append("Improve guest experience based on negative sentiment")
|
| 130 |
+
elif rating < 4.2:
|
| 131 |
+
actions.append("Improve rating drivers such as cleanliness, check-in, and value")
|
| 132 |
+
else:
|
| 133 |
+
actions.append("Satisfaction looks healthy")
|
| 134 |
+
|
| 135 |
+
opportunity_score = round((demand_score * 0.45) + (occupancy * 100 * 0.25) + (max(sentiment, -1) + 1) * 15 + (rating / 5) * 15, 2)
|
| 136 |
+
return pricing_action, suggested_price, price_gap_pct, " | ".join(actions), opportunity_score
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def send_to_n8n(payload: Dict, webhook_url: str) -> Dict:
|
| 140 |
+
if not webhook_url:
|
| 141 |
+
webhook_url = os.getenv("N8N_WEBHOOK_URL", "").strip()
|
| 142 |
+
|
| 143 |
+
if not webhook_url:
|
| 144 |
+
# Demo response so the Space works even before n8n is connected.
|
| 145 |
+
action = payload.get("pricing_recommendation", "Keep price stable")
|
| 146 |
+
if action == "Consider raising price":
|
| 147 |
+
insight = "This listing has strong demand potential and may be underpriced compared with market conditions."
|
| 148 |
+
next_step = f"Test the suggested price of ${payload.get('suggested_price', payload.get('price'))} and monitor occupancy."
|
| 149 |
+
elif action == "Consider lowering price":
|
| 150 |
+
insight = "This listing appears less competitive on price compared with similar listings."
|
| 151 |
+
next_step = "Lower the price slightly, improve listing visibility, and track whether bookings improve."
|
| 152 |
+
else:
|
| 153 |
+
insight = "This listing is reasonably aligned with comparable market conditions."
|
| 154 |
+
next_step = "Keep price stable, monitor demand, and focus on guest experience improvements."
|
| 155 |
+
|
| 156 |
+
return {
|
| 157 |
+
"status": "demo_mode",
|
| 158 |
+
"insight": insight,
|
| 159 |
+
"next_step": next_step,
|
| 160 |
+
"log": "No n8n webhook configured. Demo automation response generated inside the app."
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
try:
|
| 164 |
+
response = requests.post(webhook_url, json=payload, timeout=15)
|
| 165 |
+
response.raise_for_status()
|
| 166 |
+
try:
|
| 167 |
+
data = response.json()
|
| 168 |
+
except Exception:
|
| 169 |
+
data = {"status": "success", "insight": response.text[:300], "next_step": "Review workflow output.", "log": "n8n returned plain text."}
|
| 170 |
+
return data
|
| 171 |
+
except Exception as e:
|
| 172 |
+
return {
|
| 173 |
+
"status": "error",
|
| 174 |
+
"insight": "The pricing pipeline ran, but the n8n automation did not complete.",
|
| 175 |
+
"next_step": "Check the webhook URL, n8n workflow activation, and Respond to Webhook node.",
|
| 176 |
+
"log": str(e)
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
def run_full_pipeline(group, neighbourhood, room_type, price, availability_365, season, local_event_score, rating, sentiment, webhook_url):
|
| 181 |
+
price = float(price)
|
| 182 |
+
availability_365 = int(availability_365)
|
| 183 |
+
local_event_score = float(local_event_score)
|
| 184 |
+
rating = float(rating)
|
| 185 |
+
sentiment = float(sentiment)
|
| 186 |
+
|
| 187 |
+
comps = get_comparables(group, neighbourhood, room_type, price)
|
| 188 |
+
|
| 189 |
+
competitor_avg = safe_mean(comps["price"], default=price)
|
| 190 |
+
base_occupancy = safe_mean(comps["occupancy_rate"], default=0.50)
|
| 191 |
+
base_demand = safe_mean(comps["demand_score"], default=50)
|
| 192 |
+
base_revenue = safe_mean(comps["monthly_revenue"], default=price * 15)
|
| 193 |
+
|
| 194 |
+
# Adjusted demand logic: interpretable, stable, and presentation-friendly.
|
| 195 |
+
price_gap = ((price - competitor_avg) / competitor_avg * 100) if competitor_avg else 0
|
| 196 |
+
availability_factor = max(0, min(1, (365 - availability_365) / 365))
|
| 197 |
+
event_boost = local_event_score * 2.2
|
| 198 |
+
sentiment_boost = sentiment * 8
|
| 199 |
+
rating_boost = (rating - 4.0) * 8
|
| 200 |
+
price_penalty = max(0, price_gap) * 0.25
|
| 201 |
+
|
| 202 |
+
demand_score = float(np.clip(base_demand * 0.45 + availability_factor * 25 + event_boost + sentiment_boost + rating_boost - price_penalty, 0, 100))
|
| 203 |
+
demand_level = demand_level_from_score(demand_score)
|
| 204 |
+
|
| 205 |
+
occupancy = float(np.clip(base_occupancy * 0.55 + availability_factor * 0.25 + (demand_score / 100) * 0.20, 0.05, 0.95))
|
| 206 |
+
booked_nights = round(occupancy * 30)
|
| 207 |
+
monthly_revenue = round(price * booked_nights, 0)
|
| 208 |
+
|
| 209 |
+
pricing_action, suggested_price, price_gap_pct, final_reco, opportunity_score = build_recommendation(
|
| 210 |
+
price, competitor_avg, occupancy, demand_score, sentiment, rating
|
| 211 |
+
)
|
| 212 |
+
|
| 213 |
+
payload = {
|
| 214 |
+
"timestamp": datetime.utcnow().isoformat() + "Z",
|
| 215 |
+
"neighbourhood_group": group,
|
| 216 |
+
"neighbourhood": neighbourhood,
|
| 217 |
+
"room_type": room_type,
|
| 218 |
+
"season": season,
|
| 219 |
+
"price": price,
|
| 220 |
+
"suggested_price": suggested_price,
|
| 221 |
+
"competitor_avg_price": round(competitor_avg, 2),
|
| 222 |
+
"price_vs_competitor_pct": round(price_gap_pct, 2),
|
| 223 |
+
"availability_365": availability_365,
|
| 224 |
+
"local_event_score": local_event_score,
|
| 225 |
+
"synthetic_rating": rating,
|
| 226 |
+
"customer_sentiment_score": sentiment,
|
| 227 |
+
"estimated_occupancy_rate": round(occupancy, 3),
|
| 228 |
+
"estimated_booked_nights_month": booked_nights,
|
| 229 |
+
"estimated_monthly_revenue": monthly_revenue,
|
| 230 |
+
"demand_score": round(demand_score, 1),
|
| 231 |
+
"demand_level": demand_level,
|
| 232 |
+
"pricing_recommendation": pricing_action,
|
| 233 |
+
"final_recommendation": final_reco,
|
| 234 |
+
"opportunity_score": opportunity_score,
|
| 235 |
+
"comparable_listing_count": int(len(comps))
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
n8n_response = send_to_n8n(payload, webhook_url.strip() if webhook_url else "")
|
| 239 |
+
|
| 240 |
+
cards = f"""
|
| 241 |
+
<div class='cards'>
|
| 242 |
+
<div class='card'><div class='label'>Pricing Action</div><div class='value'>{pricing_action}</div><div class='sub'>Suggested price: ${suggested_price:,.0f}</div></div>
|
| 243 |
+
<div class='card'><div class='label'>Demand Level</div><div class='value'>{demand_level}</div><div class='sub'>Demand score: {demand_score:.1f}/100</div></div>
|
| 244 |
+
<div class='card'><div class='label'>Monthly Revenue</div><div class='value'>${monthly_revenue:,.0f}</div><div class='sub'>{booked_nights} booked nights estimated</div></div>
|
| 245 |
+
<div class='card'><div class='label'>Opportunity Score</div><div class='value'>{opportunity_score:.1f}</div><div class='sub'>{len(comps)} comparable listings</div></div>
|
| 246 |
+
</div>
|
| 247 |
+
"""
|
| 248 |
+
|
| 249 |
+
explanation = f"""
|
| 250 |
+
### Strategic Recommendation
|
| 251 |
+
|
| 252 |
+
**{final_reco}**
|
| 253 |
+
|
| 254 |
+
- Your entered price is **${price:,.0f}**.
|
| 255 |
+
- Comparable listings average **${competitor_avg:,.0f}**.
|
| 256 |
+
- Your price is **{price_gap_pct:+.1f}%** versus comparable listings.
|
| 257 |
+
- Estimated occupancy is **{occupancy:.1%}**.
|
| 258 |
+
- Estimated monthly revenue is **${monthly_revenue:,.0f}**.
|
| 259 |
+
- Demand is classified as **{demand_level}**.
|
| 260 |
+
"""
|
| 261 |
+
|
| 262 |
+
automation = f"""
|
| 263 |
+
### n8n Automation Output
|
| 264 |
+
|
| 265 |
+
**Status:** `{n8n_response.get('status', 'unknown')}`
|
| 266 |
+
|
| 267 |
+
**Insight:** {n8n_response.get('insight', 'No insight returned.')}
|
| 268 |
+
|
| 269 |
+
**Next step:** {n8n_response.get('next_step', 'No next step returned.')}
|
| 270 |
+
|
| 271 |
+
**Log:** {n8n_response.get('log', 'No log returned.')}
|
| 272 |
+
"""
|
| 273 |
+
|
| 274 |
+
# Charts
|
| 275 |
+
comp_sample = comps[["name", "neighbourhood", "room_type", "price", "occupancy_rate", "monthly_revenue", "demand_score"]].copy()
|
| 276 |
+
comp_sample = comp_sample.sort_values("price").head(100)
|
| 277 |
+
|
| 278 |
+
fig_price = px.histogram(comps, x="price", nbins=40, title="Comparable Listing Price Distribution")
|
| 279 |
+
fig_price.add_vline(x=price, line_dash="dash", annotation_text="Your price", annotation_position="top")
|
| 280 |
+
|
| 281 |
+
scatter_cols = ["price", "demand_score", "room_type", "neighbourhood"]
|
| 282 |
+
fig_demand = px.scatter(comps.dropna(subset=["price", "demand_score"]), x="price", y="demand_score", color="room_type",
|
| 283 |
+
hover_data=["neighbourhood"], title="Price vs Demand Score for Comparable Listings")
|
| 284 |
+
|
| 285 |
+
table = comp_sample.head(12).round(2)
|
| 286 |
+
payload_pretty = json.dumps(payload, indent=2)
|
| 287 |
+
|
| 288 |
+
return cards, explanation, automation, fig_price, fig_demand, table, payload_pretty
|
| 289 |
+
|
| 290 |
+
|
| 291 |
+
# -----------------------------
|
| 292 |
+
# UI
|
| 293 |
+
# -----------------------------
|
| 294 |
+
|
| 295 |
+
CSS = """
|
| 296 |
+
.gradio-container {max-width: 1280px !important; margin: auto;}
|
| 297 |
+
.hero {
|
| 298 |
+
background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 50%, #2563eb 100%);
|
| 299 |
+
border-radius: 24px;
|
| 300 |
+
padding: 34px;
|
| 301 |
+
color: white;
|
| 302 |
+
box-shadow: 0 18px 45px rgba(15, 23, 42, 0.22);
|
| 303 |
+
margin-bottom: 18px;
|
| 304 |
+
}
|
| 305 |
+
.hero h1 {font-size: 38px; margin: 0 0 8px 0;}
|
| 306 |
+
.hero p {font-size: 16px; opacity: 0.92; margin: 0; max-width: 900px;}
|
| 307 |
+
.cards {display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin: 10px 0 18px 0;}
|
| 308 |
+
.card {background: white; border: 1px solid #e5e7eb; border-radius: 18px; padding: 18px; box-shadow: 0 10px 25px rgba(15, 23, 42, 0.08);}
|
| 309 |
+
.label {font-size: 13px; text-transform: uppercase; color: #64748b; letter-spacing: .04em;}
|
| 310 |
+
.value {font-size: 24px; font-weight: 800; color: #0f172a; margin-top: 8px;}
|
| 311 |
+
.sub {font-size: 13px; color: #475569; margin-top: 8px;}
|
| 312 |
+
.panel-note {background: #eff6ff; border-left: 5px solid #2563eb; padding: 12px 14px; border-radius: 12px; color: #1e3a8a;}
|
| 313 |
+
@media (max-width: 900px) {.cards {grid-template-columns: repeat(2, minmax(0, 1fr));}}
|
| 314 |
+
@media (max-width: 600px) {.cards {grid-template-columns: 1fr;}.hero h1{font-size:28px;}}
|
| 315 |
+
"""
|
| 316 |
+
|
| 317 |
+
with gr.Blocks(css=CSS, theme=gr.themes.Soft(primary_hue="blue", neutral_hue="slate")) as demo:
|
| 318 |
+
gr.HTML("""
|
| 319 |
+
<div class='hero'>
|
| 320 |
+
<h1>๐ก AI Rental Performance Assistant</h1>
|
| 321 |
+
<p>Run a full short-term rental pricing pipeline: comparable listings, demand scoring, revenue estimation, pricing recommendation, and n8n automation response.</p>
|
| 322 |
+
</div>
|
| 323 |
+
""")
|
| 324 |
+
|
| 325 |
+
with gr.Row():
|
| 326 |
+
with gr.Column(scale=1):
|
| 327 |
+
gr.Markdown("### 1) Listing Inputs")
|
| 328 |
+
group = gr.Dropdown(choices=NEIGH_GROUPS, value=NEIGH_GROUPS[0] if NEIGH_GROUPS else None, label="Neighbourhood Group")
|
| 329 |
+
neighbourhood = gr.Dropdown(choices=sorted(full_df.loc[full_df["neighbourhood_group"] == (NEIGH_GROUPS[0] if NEIGH_GROUPS else ""), "neighbourhood"].dropna().unique().tolist()), label="Neighbourhood")
|
| 330 |
+
room_type = gr.Dropdown(choices=ROOM_TYPES, value=ROOM_TYPES[0] if ROOM_TYPES else None, label="Room Type")
|
| 331 |
+
price = gr.Slider(20, 800, value=150, step=5, label="Current Nightly Price ($)")
|
| 332 |
+
availability_365 = gr.Slider(0, 365, value=180, step=1, label="Availability Over Next 365 Days")
|
| 333 |
+
season = gr.Dropdown(choices=SEASONS, value=SEASONS[0] if SEASONS else "Summer", label="Season")
|
| 334 |
+
local_event_score = gr.Slider(0, 10, value=5, step=0.1, label="Local Event Score (0 = low, 10 = major event period)")
|
| 335 |
+
rating = gr.Slider(1, 5, value=4.4, step=0.05, label="Guest Rating")
|
| 336 |
+
sentiment = gr.Slider(-1, 1, value=0.25, step=0.01, label="Customer Sentiment Score")
|
| 337 |
+
|
| 338 |
+
gr.Markdown("### 2) n8n Webhook")
|
| 339 |
+
gr.HTML("<div class='panel-note'>Paste your n8n production webhook URL here, or leave blank to run demo mode.</div>")
|
| 340 |
+
webhook_url = gr.Textbox(label="n8n Webhook URL", placeholder="https://your-n8n-domain/webhook/airbnb-pipeline", type="password")
|
| 341 |
+
run_btn = gr.Button("๐ Run Full Pipeline", variant="primary", size="lg")
|
| 342 |
+
|
| 343 |
+
with gr.Column(scale=2):
|
| 344 |
+
gr.Markdown("### 3) Pipeline Output")
|
| 345 |
+
cards = gr.HTML()
|
| 346 |
+
explanation = gr.Markdown()
|
| 347 |
+
automation = gr.Markdown()
|
| 348 |
+
|
| 349 |
+
with gr.Tabs():
|
| 350 |
+
with gr.Tab("๐ Charts"):
|
| 351 |
+
with gr.Row():
|
| 352 |
+
fig_price = gr.Plot()
|
| 353 |
+
fig_demand = gr.Plot()
|
| 354 |
+
with gr.Tab("๐๏ธ Comparable Listings"):
|
| 355 |
+
comp_table = gr.Dataframe(label="Top comparable listings", interactive=False)
|
| 356 |
+
with gr.Tab("๐งพ JSON Sent to n8n"):
|
| 357 |
+
payload_view = gr.Code(language="json", label="Pipeline payload")
|
| 358 |
+
|
| 359 |
+
group.change(fn=neighbourhood_choices, inputs=group, outputs=neighbourhood)
|
| 360 |
+
|
| 361 |
+
run_btn.click(
|
| 362 |
+
fn=run_full_pipeline,
|
| 363 |
+
inputs=[group, neighbourhood, room_type, price, availability_365, season, local_event_score, rating, sentiment, webhook_url],
|
| 364 |
+
outputs=[cards, explanation, automation, fig_price, fig_demand, comp_table, payload_view]
|
| 365 |
+
)
|
| 366 |
+
|
| 367 |
+
gr.Markdown("""
|
| 368 |
+
---
|
| 369 |
+
**Project logic:** The app finds comparable listings, estimates demand and revenue, produces a pricing recommendation, then sends the full result to n8n. n8n should return a JSON response with `status`, `insight`, `next_step`, and `log`.
|
| 370 |
+
""")
|
| 371 |
+
|
| 372 |
+
if __name__ == "__main__":
|
| 373 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio>=4.44.0
|
| 2 |
+
pandas>=2.0.0
|
| 3 |
+
numpy>=1.24.0
|
| 4 |
+
plotly>=5.18.0
|
| 5 |
+
requests>=2.31.0
|
synthetic_airbnb_project_data.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4e63f75596406a07ad35fb85e63a803708244e352792c6dcdf323bf788c00b19
|
| 3 |
+
size 17968855
|