import gradio as gr import pandas as pd import matplotlib.pyplot as plt df = pd.read_csv("hotel_final_dataset.csv") hotels = sorted(df["hotel_name"].dropna().unique().tolist()) def analyze(hotel): data = df[df["hotel_name"] == hotel].copy() avg_rating = round(data["avg_rating"].mean(), 2) sentiment = round(data["sentiment_score"].mean(), 2) occupancy = round(data["occupancy_rate"].mean(), 2) price = round(data["price_per_night"].mean(), 2) demand = round(data["demand_index"].mean(), 2) base_rec = data["pricing_recommendation"].mode().iloc[0] if sentiment < 0: recommendation = f"{base_rec} — but improve customer satisfaction first" elif occupancy > 0.95: recommendation = f"{base_rec} — strong demand supports price increase" else: recommendation = base_rec fig, ax = plt.subplots(figsize=(8, 4)) fig.patch.set_facecolor('#111111') ax.set_facecolor('#111111') ax.plot(data["month"], data["booking_count"], marker="o") ax.set_title("Booking Trend", color='white') ax.set_xlabel("Month", color='white') ax.set_ylabel("Booking Count", color='white') ax.tick_params(colors='white') plt.xticks(rotation=45) plt.tight_layout() return avg_rating, sentiment, occupancy, price, demand, recommendation, fig with gr.Blocks() as demo: gr.Markdown("# AI-Driven Hotel Pricing Dashboard") gr.Markdown("Analyze hotel performance using sentiment, demand, pricing, and booking trends.") with gr.Row(): hotel_input = gr.Dropdown(choices=hotels, label="Select Hotel", value=hotels[0]) with gr.Row(): avg_rating_output = gr.Textbox(label="Average Rating") sentiment_output = gr.Textbox(label="Customer Sentiment Score") occupancy_output = gr.Textbox(label="Occupancy Rate") with gr.Row(): price_output = gr.Textbox(label="Average Price per Night") demand_output = gr.Textbox(label="Demand Level Index") recommendation_output = gr.Textbox(label="Pricing Recommendation") plot_output = gr.Plot(label="Booking Trend") submit_btn = gr.Button("Run Analysis") submit_btn.click( fn=analyze, inputs=hotel_input, outputs=[ avg_rating_output, sentiment_output, occupancy_output, price_output, demand_output, recommendation_output, plot_output ] ) demo.launch()