Spaces:
Sleeping
Sleeping
Download app.py from Suhani0409/Bot56: direct link, hf CLI and curl.
- Browser
- Download file 2.19 kB
-
https://huggingface.co/spaces/Suhani0409/Bot56/resolve/main/app.py
- Command line
-
hf download hf://spaces/Suhani0409/Bot56/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Suhani0409/Bot56/resolve/main/app.py
2.19 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/laxmimerit/All-CSV-ML-Data-Files-Download/master/IMDB-Movie-Data.csv" | |
| df = pd.read_csv(url) | |
| # --- Visualization Functions --- | |
| def show_data(n): | |
| """Show top n rows of the dataset.""" | |
| return df.head(n) | |
| def plot_visualizations(choice): | |
| """Generate different plots based on user choice.""" | |
| plt.figure(figsize=(8, 5)) | |
| if choice == "Rating Distribution": | |
| sns.histplot(df["Rating"], bins=15, kde=True) | |
| plt.title("Distribution of Movie Ratings") | |
| elif choice == "Top 10 Directors": | |
| top_directors = df["Director"].value_counts().head(10) | |
| sns.barplot(x=top_directors.values, y=top_directors.index) | |
| plt.title("Top 10 Directors by Movie Count") | |
| elif choice == "Genre Frequency": | |
| all_genres = df["Genre"].str.split(",").explode().str.strip() | |
| top_genres = all_genres.value_counts().head(10) | |
| sns.barplot(x=top_genres.values, y=top_genres.index) | |
| plt.title("Top 10 Movie Genres") | |
| elif choice == "Revenue vs Rating": | |
| sns.scatterplot(x="Rating", y="Revenue (Millions)", data=df) | |
| plt.title("Revenue vs Rating") | |
| plt.tight_layout() | |
| return plt.gcf() | |
| # --- Gradio Interface --- | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# 🎬 IMDB Movie Data Explorer") | |
| gr.Markdown("Explore insights from the IMDB Movie Dataset with visualizations.") | |
| with gr.Tab("📊 View Data"): | |
| n_slider = gr.Slider(5, 50, value=10, step=5, label="Select number of rows") | |
| data_output = gr.Dataframe(label="Dataset Preview") | |
| n_slider.change(show_data, inputs=n_slider, outputs=data_output) | |
| with gr.Tab("📈 Visualize"): | |
| choice = gr.Radio( | |
| ["Rating Distribution", "Top 10 Directors", "Genre Frequency", "Revenue vs Rating"], | |
| label="Select Visualization", | |
| ) | |
| plot_output = gr.Plot(label="Visualization") | |
| choice.change(plot_visualizations, inputs=choice, outputs=plot_output) | |
| gr.Markdown("Made with ❤️ using Gradio + Seaborn") | |
| demo.launch() | |