Spaces:
Sleeping
Sleeping
| 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() | |