Spaces:
Runtime error
Runtime error
Download app.py from Suhani0409/Apple12: direct link, hf CLI and curl.
- Browser
- Download file 2.61 kB
-
https://huggingface.co/spaces/Suhani0409/Apple12/resolve/main/app.py
- Command line
-
hf download hf://spaces/Suhani0409/Apple12/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Suhani0409/Apple12/resolve/main/app.py
2.61 kB
| import gradio as gr | |
| import pandas as pd | |
| import seaborn as sns | |
| import matplotlib.pyplot as plt | |
| # Load dataset | |
| URL = "https://raw.githubusercontent.com/sachin365123/CSV-files-for-Data-Science-and-Machine-Learning/main/wine_fraud.csv" | |
| df = pd.read_csv(URL) | |
| # Pre-processing / cleaning | |
| df = df.copy() | |
| # Example: drop duplicates, convert date columns, fill missing values | |
| df = df.drop_duplicates() | |
| # If there is a “date” column, convert to datetime: | |
| # df["date_column"] = pd.to_datetime(df["date_column"], errors="coerce") | |
| # For numeric columns: | |
| for col in df.select_dtypes(include=["object"]).columns: | |
| # try converting to numeric | |
| df[col] = pd.to_numeric(df[col], errors="ignore") | |
| # Basic info | |
| print(df.info()) | |
| print(df.describe()) | |
| # Visualization functions | |
| def preview_data(n_rows: int): | |
| return df.head(n_rows) | |
| def plot_vis(choice: str): | |
| plt.figure(figsize=(8,5)) | |
| if choice == "Distribution of Wine Price": # replace with actual column | |
| if "price" in df.columns: | |
| sns.histplot(df["price"], bins=30, kde=True) | |
| plt.title("Distribution of Wine Price") | |
| else: | |
| plt.text(0.5,0.5,"‘price’ column not found", ha='center') | |
| elif choice == "Fraud vs Non-Fraud Count": | |
| if "fraud_flag" in df.columns: | |
| sns.countplot(x="fraud_flag", data=df) | |
| plt.title("Fraud vs Non-Fraud Count") | |
| else: | |
| plt.text(0.5,0.5,"‘fraud_flag’ column not found", ha='center') | |
| elif choice == "Correlation Heatmap": | |
| sns.heatmap(df.select_dtypes(include=["number"]).corr(), annot=True, fmt=".2f", cmap="coolwarm") | |
| plt.title("Correlation Heatmap (numeric features)") | |
| else: | |
| plt.text(0.5,0.5,"Unknown choice", ha='center') | |
| plt.tight_layout() | |
| return plt.gcf() | |
| # Build Gradio interface | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# 🍷 Wine Fraud Data Explorer") | |
| gr.Markdown("Explore and visualize the wine-fraud dataset.") | |
| with gr.Tab("📋 Data Preview"): | |
| n = gr.Slider(5, 100, value=10, step=5, label="Number of rows to show") | |
| table = gr.Dataframe(label="Dataset Preview") | |
| n.change(preview_data, inputs=n, outputs=table) | |
| with gr.Tab("📊 Visualizations"): | |
| vis_choice = gr.Radio( | |
| ["Distribution of Wine Price", "Fraud vs Non-Fraud Count", "Correlation Heatmap"], | |
| label="Select a visualization" | |
| ) | |
| plot = gr.Plot(label="Visualization") | |
| vis_choice.change(plot_vis, inputs=vis_choice, outputs=plot) | |
| gr.Markdown("Built with Gradio + seaborn + matplotlib") | |
| demo.launch() | |