csv-test / app.py
bbbdbbb's picture
Update app.py
fefc6e0 verified
raw
history blame
1.09 kB
import os
os.system("pip uninstall -y gradio")
os.system("pip install gradio==3.50.2")
import pandas as pd
import matplotlib.pyplot as plt
import gradio as gr
def analyze_csv(file):
df = pd.read_csv(file.name)
# 统计分析
stats = df.describe().loc[["mean", "std", "min", "max"]].round(2).to_string()
# 生成图像:Income vs SpendingScore
plt.figure(figsize=(6, 4))
plt.scatter(df["Income"], df["SpendingScore"], alpha=0.7)
plt.title("Income vs Spending Score")
plt.xlabel("Income")
plt.ylabel("Spending Score")
plt.grid(True)
img_path = "income_vs_score.png"
plt.savefig(img_path)
plt.close()
return stats, img_path
iface = gr.Interface(
fn=analyze_csv,
inputs=gr.File(label="Upload CSV File", file_types=[".csv"]),
outputs=[gr.Text(label="📊 Statistical Summary"), gr.Image(label="📈 Income vs Spending Score")],
title="📊 表格分析大模型",
description="上传一个CSV表格,我将输出统计分析结果并展示一张图表。"
)
if __name__ == "__main__":
iface.launch()