File size: 1,031 Bytes
a21641a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import gradio as gr
import pandas as pd
import matplotlib.pyplot as plt

def visualize(data):
    # Convert to DataFrame (list of dicts or rows)
    df = pd.DataFrame(data, columns=["Name", "Age", "Score"])

    # Bar chart
    plt.figure(figsize=(5,4))
    plt.bar(df["Name"], df["Score"], color="skyblue")
    plt.title("Scores by Person")
    plt.xlabel("Name")
    plt.ylabel("Score")
    plt.tight_layout()
    plt.savefig("bar.png")
    plt.close()

    # Pie chart
    plt.figure(figsize=(4,4))
    plt.pie(df["Score"], labels=df["Name"], autopct="%1.1f%%")
    plt.title("Score Distribution")
    plt.savefig("pie.png")
    plt.close()

    return ["bar.png", "pie.png"]

# Gradio interface
gr.Interface(
    fn=visualize,
    inputs=gr.Dataframe(
        headers=["Name", "Age", "Score"],
        row_count=3,                 # make sure it accepts 3 rows
        col_count=3,
        label="Enter data for 3 people"
    ),
    outputs=gr.Gallery(columns=2, label="Charts"),
    title="People Score Visualizer"
).launch()