Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,44 +3,54 @@ import pandas as pd
|
|
| 3 |
import seaborn as sns
|
| 4 |
import matplotlib.pyplot as plt
|
| 5 |
|
| 6 |
-
# Load dataset
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
plt.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
plt.tight_layout()
|
| 19 |
return plt.gcf()
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
plot_btn = gr.Button("Generate Plot")
|
| 41 |
-
plot_output = gr.Plot(label="Visualization Output")
|
| 42 |
-
|
| 43 |
-
plot_btn.click(visualize_data, inputs=[x_col, y_col], outputs=plot_output)
|
| 44 |
|
| 45 |
-
# Launch app
|
| 46 |
demo.launch()
|
|
|
|
| 3 |
import seaborn as sns
|
| 4 |
import matplotlib.pyplot as plt
|
| 5 |
|
| 6 |
+
# Load dataset
|
| 7 |
+
url = "https://raw.githubusercontent.com/laxmimerit/All-CSV-ML-Data-Files-Download/master/IMDB-Movie-Data.csv"
|
| 8 |
+
df = pd.read_csv(url)
|
| 9 |
+
|
| 10 |
+
# --- Visualization Functions ---
|
| 11 |
+
def show_data(n):
|
| 12 |
+
"""Show top n rows of the dataset."""
|
| 13 |
+
return df.head(n)
|
| 14 |
+
|
| 15 |
+
def plot_visualizations(choice):
|
| 16 |
+
"""Generate different plots based on user choice."""
|
| 17 |
+
plt.figure(figsize=(8, 5))
|
| 18 |
+
if choice == "Rating Distribution":
|
| 19 |
+
sns.histplot(df["Rating"], bins=15, kde=True)
|
| 20 |
+
plt.title("Distribution of Movie Ratings")
|
| 21 |
+
elif choice == "Top 10 Directors":
|
| 22 |
+
top_directors = df["Director"].value_counts().head(10)
|
| 23 |
+
sns.barplot(x=top_directors.values, y=top_directors.index)
|
| 24 |
+
plt.title("Top 10 Directors by Movie Count")
|
| 25 |
+
elif choice == "Genre Frequency":
|
| 26 |
+
all_genres = df["Genre"].str.split(",").explode().str.strip()
|
| 27 |
+
top_genres = all_genres.value_counts().head(10)
|
| 28 |
+
sns.barplot(x=top_genres.values, y=top_genres.index)
|
| 29 |
+
plt.title("Top 10 Movie Genres")
|
| 30 |
+
elif choice == "Revenue vs Rating":
|
| 31 |
+
sns.scatterplot(x="Rating", y="Revenue (Millions)", data=df)
|
| 32 |
+
plt.title("Revenue vs Rating")
|
| 33 |
plt.tight_layout()
|
| 34 |
return plt.gcf()
|
| 35 |
|
| 36 |
+
# --- Gradio Interface ---
|
| 37 |
+
with gr.Blocks() as demo:
|
| 38 |
+
gr.Markdown("# 🎬 IMDB Movie Data Explorer")
|
| 39 |
+
gr.Markdown("Explore insights from the IMDB Movie Dataset with visualizations.")
|
| 40 |
+
|
| 41 |
+
with gr.Tab("📊 View Data"):
|
| 42 |
+
n_slider = gr.Slider(5, 50, value=10, step=5, label="Select number of rows")
|
| 43 |
+
data_output = gr.Dataframe(label="Dataset Preview")
|
| 44 |
+
n_slider.change(show_data, inputs=n_slider, outputs=data_output)
|
| 45 |
+
|
| 46 |
+
with gr.Tab("📈 Visualize"):
|
| 47 |
+
choice = gr.Radio(
|
| 48 |
+
["Rating Distribution", "Top 10 Directors", "Genre Frequency", "Revenue vs Rating"],
|
| 49 |
+
label="Select Visualization",
|
| 50 |
+
)
|
| 51 |
+
plot_output = gr.Plot(label="Visualization")
|
| 52 |
+
choice.change(plot_visualizations, inputs=choice, outputs=plot_output)
|
| 53 |
+
|
| 54 |
+
gr.Markdown("Made with ❤️ using Gradio + Seaborn")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
|
|
|
| 56 |
demo.launch()
|