matesoft's picture
Create app.py
a21641a verified
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()