TKM03 commited on
Commit
940863d
·
verified ·
1 Parent(s): 178ecb1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -5
app.py CHANGED
@@ -1,12 +1,50 @@
1
- import streamlit as st
2
  from datasets import load_dataset
3
  import pandas as pd
 
4
 
5
- st.title("Explore Hugging Face Dataset")
6
  dataset = load_dataset("ag_news", split="train[:1000]")
7
 
 
8
  df = pd.DataFrame(dataset)
9
- st.write("Sample data:", df.head())
10
 
11
- st.write("Category Distribution")
12
- st.bar_chart(df["label"].value_counts())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
  from datasets import load_dataset
3
  import pandas as pd
4
+ import matplotlib.pyplot as plt
5
 
6
+ # Load a dataset (you can change this to any HF dataset)
7
  dataset = load_dataset("ag_news", split="train[:1000]")
8
 
9
+ # Convert to DataFrame
10
  df = pd.DataFrame(dataset)
 
11
 
12
+ # Label map for better readability
13
+ label_map = {
14
+ 0: "World",
15
+ 1: "Sports",
16
+ 2: "Business",
17
+ 3: "Sci/Tech"
18
+ }
19
+ df["label_name"] = df["label"].map(label_map)
20
+
21
+ def preview_data(n_rows):
22
+ return df.head(n_rows)
23
+
24
+ def plot_distribution():
25
+ counts = df["label_name"].value_counts()
26
+ fig, ax = plt.subplots()
27
+ counts.plot(kind="bar", ax=ax, color="skyblue")
28
+ ax.set_title("Label Distribution")
29
+ ax.set_ylabel("Count")
30
+ ax.set_xlabel("Category")
31
+ return fig
32
+
33
+ with gr.Blocks() as demo:
34
+ gr.Markdown("# 🧠 AG News Dataset Explorer")
35
+ gr.Markdown("Explore the AG News dataset from Hugging Face. Useful for data engineers and NLP practitioners.")
36
+
37
+ with gr.Row():
38
+ num_slider = gr.Slider(1, 20, value=5, label="Number of Rows")
39
+ data_output = gr.Dataframe()
40
+
41
+ show_data_btn = gr.Button("Show Data")
42
+ show_data_btn.click(preview_data, inputs=[num_slider], outputs=[data_output])
43
+
44
+ gr.Markdown("## 📊 Class Distribution")
45
+ dist_btn = gr.Button("Show Distribution Chart")
46
+ chart_output = gr.Plot()
47
+ dist_btn.click(plot_distribution, outputs=[chart_output])
48
+
49
+ # Launch app
50
+ demo.launch()