File size: 1,061 Bytes
40110db
 
 
 
b8fc223
 
40110db
 
 
b8fc223
40110db
b8fc223
40110db
 
 
 
 
 
 
 
 
 
 
 
b8fc223
40110db
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import pandas as pd

# 文件处理函数
def process_file(file):
    if file is None:
        return "请上传文件"
    
    # 假设是 CSV 文件
    try:
        df = pd.read_csv(file.name)
    except:
        return "无法读取文件,请上传 CSV 文件"
    
    # 示例处理:统计每一列的均值
    summary = df.mean().to_frame(name="Mean").reset_index()
    
    # 保存处理后的结果
    output_file = "processed_result.csv"
    summary.to_csv(output_file, index=False)
    
    return summary, output_file

# Gradio 界面
with gr.Blocks() as demo:
    gr.Markdown("# Dobot 数据处理演示")
    gr.Markdown("上传 CSV 文件,统计每一列均值,并可下载结果。")
    
    file_input = gr.File(label="上传 CSV 文件")
    run_btn = gr.Button("处理文件")
    output_table = gr.Dataframe(headers=None, label="处理结果")
    download_btn = gr.File(label="下载处理结果")
    
    run_btn.click(process_file, inputs=file_input, outputs=[output_table, download_btn])

demo.launch()