Suhani0409 commited on
Commit
253bb1b
·
verified ·
1 Parent(s): 6179db6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -36
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 automatically from GitHub
7
- CSV_URL = "https://raw.githubusercontent.com/datablist/sample-csv-files/main/files/people/people-100.csv"
8
-
9
- def load_data():
10
- df = pd.read_csv(CSV_URL)
11
- return df.head(10)
12
-
13
- def visualize_data(column_x, column_y):
14
- df = pd.read_csv(CSV_URL)
15
- plt.figure(figsize=(7, 5))
16
- sns.scatterplot(x=df[column_x], y=df[column_y])
17
- plt.title(f"Scatter Plot: {column_x} vs {column_y}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  plt.tight_layout()
19
  return plt.gcf()
20
 
21
- def get_column_names():
22
- df = pd.read_csv(CSV_URL)
23
- return list(df.columns)
24
-
25
- # Dropdown options
26
- cols = get_column_names()
27
-
28
- # Gradio interface
29
- with gr.Blocks(title="CSV Visualizer using Gradio") as demo:
30
- gr.Markdown("# 📊 CSV Visualizer\nUpload from GitHub and Explore the Data!")
31
-
32
- with gr.Tab("View Data"):
33
- view_btn = gr.Button("Load Data")
34
- data_output = gr.Dataframe(label="Data Preview")
35
- view_btn.click(load_data, outputs=data_output)
36
-
37
- with gr.Tab("Visualize Data"):
38
- x_col = gr.Dropdown(choices=cols, label="Select X-axis Column")
39
- y_col = gr.Dropdown(choices=cols, label="Select Y-axis Column")
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()