risdom / app.py
yosuke-i's picture
Update app.py
a865b90 verified
raw
history blame
No virus
882 Bytes
import gradio as gr
import pandas as pd
import tempfile
import os
def process_csv(file_obj):
df = pd.read_csv(file_obj)
df['age'] = df['age'] * 2
# 一時ファイルを作成して結果を書き込む
with tempfile.NamedTemporaryFile(delete=False, suffix='.csv', mode='w+') as tmp_file:
df.to_csv(tmp_file.name, index=False)
# 一時ファイルのパスを保持
temp_file_path = tmp_file.name
# 一時ファイルのパスを返却
return temp_file_path
iface = gr.Interface(fn=process_csv,
inputs=gr.File(label="Upload CSV"),
outputs=gr.File(label="Download Processed CSV", type="file"), # 'type'を'file'に設定
description="Upload a CSV with 'name' and 'age' columns. This app will double the 'age' and let you download the processed CSV.")
iface.launch()