matesoft commited on
Commit
a21641a
·
verified ·
1 Parent(s): 96272f5

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import matplotlib.pyplot as plt
4
+
5
+ def visualize(data):
6
+ # Convert to DataFrame (list of dicts or rows)
7
+ df = pd.DataFrame(data, columns=["Name", "Age", "Score"])
8
+
9
+ # Bar chart
10
+ plt.figure(figsize=(5,4))
11
+ plt.bar(df["Name"], df["Score"], color="skyblue")
12
+ plt.title("Scores by Person")
13
+ plt.xlabel("Name")
14
+ plt.ylabel("Score")
15
+ plt.tight_layout()
16
+ plt.savefig("bar.png")
17
+ plt.close()
18
+
19
+ # Pie chart
20
+ plt.figure(figsize=(4,4))
21
+ plt.pie(df["Score"], labels=df["Name"], autopct="%1.1f%%")
22
+ plt.title("Score Distribution")
23
+ plt.savefig("pie.png")
24
+ plt.close()
25
+
26
+ return ["bar.png", "pie.png"]
27
+
28
+ # Gradio interface
29
+ gr.Interface(
30
+ fn=visualize,
31
+ inputs=gr.Dataframe(
32
+ headers=["Name", "Age", "Score"],
33
+ row_count=3, # make sure it accepts 3 rows
34
+ col_count=3,
35
+ label="Enter data for 3 people"
36
+ ),
37
+ outputs=gr.Gallery(columns=2, label="Charts"),
38
+ title="People Score Visualizer"
39
+ ).launch()