Download app.py from basaktamer/Waiter_Tips_Data_Visualization: direct link, hf CLI and curl.
- Browser
- Download file 1.7 kB
-
https://huggingface.co/spaces/basaktamer/Waiter_Tips_Data_Visualization/resolve/main/app.py
- Command line
-
hf download hf://spaces/basaktamer/Waiter_Tips_Data_Visualization/app.py
-
curl -L -o app.py https://huggingface.co/spaces/basaktamer/Waiter_Tips_Data_Visualization/resolve/main/app.py
1.7 kB
| import streamlit as st | |
| import pandas as pd | |
| import plotly.express as px | |
| import seaborn as sns | |
| # 1. Page Config | |
| st.set_page_config(page_title="Waiter Tips Analysis", layout="wide") | |
| # 2. Sidebar: Aim & Target (From your Notebook) | |
| st.sidebar.title("Project Overview") | |
| st.sidebar.markdown(""" | |
| **Aim:** Identify key factors influencing tipping behavior. | |
| **Target:** - Customer Profiling | |
| - Temporal Analysis | |
| - Correlation Mapping | |
| - Interactive Visualization | |
| """) | |
| # 3. Load Data | |
| def load_data(): | |
| # You can also use pd.read_csv("waitertips.csv") if you upload the file | |
| df = sns.load_dataset('tips') | |
| df['tip_pct'] = (df['tip'] / df['total_bill']) * 100 | |
| return df | |
| df = load_data() | |
| # 4. Main Title | |
| st.title("🍽️ Waiter Tips Data Visualization") | |
| st.write("Exploration of restaurant transactions and tipping patterns.") | |
| # 5. Key Metrics (The "A" you added!) | |
| col1, col2, col3 = st.columns(3) | |
| col1.metric("Avg. Total Bill", f"${df['total_bill'].mean():.2f}") | |
| col2.metric("Avg. Tip", f"${df['tip'].mean():.2f}") | |
| col3.metric("Avg. Tip %", f"{df['tip_pct'].mean():.2f}%") | |
| # 6. Interactive Plotly Chart (The "B" you added!) | |
| st.subheader("Interactive Tip Analysis") | |
| fig = px.scatter(df, x="total_bill", y="tip", color="sex", | |
| size="size", hover_data=['day', 'time'], | |
| trendline="ols", title="Total Bill vs Tip (by Gender)") | |
| st.plotly_chart(fig, use_container_width=True) | |
| # 7. Advanced Visualization (Sunburst) | |
| st.subheader("Hierarchical View of Tips") | |
| fig_sun = px.sunburst(df, path=['day', 'time', 'sex'], values='tip') | |
| st.plotly_chart(fig_sun, use_container_width=True) | |
| st.write("---") | |
| st.write("Created for my Data Visualization Portfolio.") |