bbbdbbb commited on
Commit
375b8fb
·
verified ·
1 Parent(s): f3fee83

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -6,30 +6,35 @@ import gradio as gr
6
  def analyze_csv(file):
7
  df = pd.read_csv(file.name)
8
 
9
- # 统计分析
10
  stats = df.describe().loc[["mean", "std", "min", "max"]].round(2).to_string()
11
 
12
- # 生成图像:Income vs SpendingScore
13
  plt.figure(figsize=(6, 4))
14
  plt.scatter(df["Income"], df["SpendingScore"], alpha=0.7)
15
  plt.title("Income vs Spending Score")
16
  plt.xlabel("Income")
17
  plt.ylabel("Spending Score")
18
  plt.grid(True)
19
-
20
  img_path = "income_vs_score.png"
21
  plt.savefig(img_path)
22
  plt.close()
23
 
24
- return stats, img_path
 
 
 
25
 
26
  iface = gr.Interface(
27
  fn=analyze_csv,
28
  inputs=gr.File(label="Upload CSV File", file_types=[".csv"]),
29
- outputs=[gr.Text(label="📊 Statistical Summary"), gr.Image(label="📈 Income vs Spending Score")],
 
 
 
30
  title="📊 表格分析大模型",
31
  description="上传一个CSV表格,我将输出统计分析结果并展示一张图表。"
32
  )
33
 
 
34
  if __name__ == "__main__":
35
  iface.launch()
 
6
  def analyze_csv(file):
7
  df = pd.read_csv(file.name)
8
 
 
9
  stats = df.describe().loc[["mean", "std", "min", "max"]].round(2).to_string()
10
 
11
+ # 生成图像
12
  plt.figure(figsize=(6, 4))
13
  plt.scatter(df["Income"], df["SpendingScore"], alpha=0.7)
14
  plt.title("Income vs Spending Score")
15
  plt.xlabel("Income")
16
  plt.ylabel("Spending Score")
17
  plt.grid(True)
 
18
  img_path = "income_vs_score.png"
19
  plt.savefig(img_path)
20
  plt.close()
21
 
22
+ return {
23
+ "📊 Summary": stats,
24
+ "📈 Chart": img_path
25
+ }
26
 
27
  iface = gr.Interface(
28
  fn=analyze_csv,
29
  inputs=gr.File(label="Upload CSV File", file_types=[".csv"]),
30
+ outputs=[
31
+ gr.Text(label="📊 Summary"),
32
+ gr.Image(label="📈 Chart")
33
+ ],
34
  title="📊 表格分析大模型",
35
  description="上传一个CSV表格,我将输出统计分析结果并展示一张图表。"
36
  )
37
 
38
+
39
  if __name__ == "__main__":
40
  iface.launch()