Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,66 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
|
|
|
| 3 |
|
| 4 |
df = pd.read_csv("hotel_final_dataset.csv")
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
| 7 |
|
| 8 |
def analyze(hotel):
|
| 9 |
-
data = df[df["hotel_name"] == hotel]
|
| 10 |
|
| 11 |
avg_rating = round(data["avg_rating"].mean(), 2)
|
| 12 |
sentiment = round(data["sentiment_score"].mean(), 2)
|
| 13 |
occupancy = round(data["occupancy_rate"].mean(), 2)
|
| 14 |
price = round(data["price_per_night"].mean(), 2)
|
| 15 |
demand = round(data["demand_index"].mean(), 2)
|
| 16 |
-
recommendation = data["pricing_recommendation"].iloc[0]
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
)
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
|
| 5 |
df = pd.read_csv("hotel_final_dataset.csv")
|
| 6 |
|
| 7 |
+
# Optional: sort if month is stored in orderable form
|
| 8 |
+
# If month is text like Jan, Feb, Mar, keep as-is for now
|
| 9 |
+
hotels = sorted(df["hotel_name"].dropna().unique().tolist())
|
| 10 |
|
| 11 |
def analyze(hotel):
|
| 12 |
+
data = df[df["hotel_name"] == hotel].copy()
|
| 13 |
|
| 14 |
avg_rating = round(data["avg_rating"].mean(), 2)
|
| 15 |
sentiment = round(data["sentiment_score"].mean(), 2)
|
| 16 |
occupancy = round(data["occupancy_rate"].mean(), 2)
|
| 17 |
price = round(data["price_per_night"].mean(), 2)
|
| 18 |
demand = round(data["demand_index"].mean(), 2)
|
| 19 |
+
recommendation = data["pricing_recommendation"].mode().iloc[0]
|
| 20 |
+
|
| 21 |
+
fig, ax = plt.subplots(figsize=(8, 4))
|
| 22 |
+
ax.plot(data["month"], data["booking_count"], marker="o")
|
| 23 |
+
ax.set_title("Booking Trend")
|
| 24 |
+
ax.set_xlabel("Month")
|
| 25 |
+
ax.set_ylabel("Booking Count")
|
| 26 |
+
plt.xticks(rotation=45)
|
| 27 |
+
plt.tight_layout()
|
| 28 |
+
|
| 29 |
+
return avg_rating, sentiment, occupancy, price, demand, recommendation, fig
|
| 30 |
+
|
| 31 |
+
with gr.Blocks() as demo:
|
| 32 |
+
gr.Markdown("# Hotel Pricing & Demand Dashboard")
|
| 33 |
+
gr.Markdown("Analyze hotel performance using sentiment, demand, pricing, and booking trends.")
|
| 34 |
+
|
| 35 |
+
with gr.Row():
|
| 36 |
+
hotel_input = gr.Dropdown(choices=hotels, label="Select Hotel", value=hotels[0])
|
| 37 |
+
|
| 38 |
+
with gr.Row():
|
| 39 |
+
avg_rating_output = gr.Textbox(label="Average Rating")
|
| 40 |
+
sentiment_output = gr.Textbox(label="Sentiment Score")
|
| 41 |
+
occupancy_output = gr.Textbox(label="Occupancy Rate")
|
| 42 |
+
|
| 43 |
+
with gr.Row():
|
| 44 |
+
price_output = gr.Textbox(label="Average Price per Night")
|
| 45 |
+
demand_output = gr.Textbox(label="Demand Index")
|
| 46 |
+
recommendation_output = gr.Textbox(label="Pricing Recommendation")
|
| 47 |
+
|
| 48 |
+
plot_output = gr.Plot(label="Booking Trend")
|
| 49 |
+
|
| 50 |
+
submit_btn = gr.Button("Run Analysis")
|
| 51 |
+
|
| 52 |
+
submit_btn.click(
|
| 53 |
+
fn=analyze,
|
| 54 |
+
inputs=hotel_input,
|
| 55 |
+
outputs=[
|
| 56 |
+
avg_rating_output,
|
| 57 |
+
sentiment_output,
|
| 58 |
+
occupancy_output,
|
| 59 |
+
price_output,
|
| 60 |
+
demand_output,
|
| 61 |
+
recommendation_output,
|
| 62 |
+
plot_output
|
| 63 |
+
]
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
demo.launch()
|