Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
from io import BytesIO
|
|
|
4 |
|
5 |
def double_age(csv_file):
|
6 |
# ファイル名を取得
|
@@ -12,18 +13,17 @@ def double_age(csv_file):
|
|
12 |
# ageカラムの値を2倍にする
|
13 |
df['age'] = df['age'] * 2
|
14 |
|
15 |
-
#
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
return csv_bytesio
|
22 |
|
23 |
interface = gr.Interface(
|
24 |
fn=double_age,
|
25 |
inputs=gr.File(label="CSVファイルをアップロード"),
|
26 |
-
outputs=gr.File(label="ダウンロード"),
|
27 |
allow_flagging="never"
|
28 |
)
|
29 |
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
from io import BytesIO
|
4 |
+
import tempfile
|
5 |
|
6 |
def double_age(csv_file):
|
7 |
# ファイル名を取得
|
|
|
13 |
# ageカラムの値を2倍にする
|
14 |
df['age'] = df['age'] * 2
|
15 |
|
16 |
+
# 一時ファイルを作成し、CSVデータを書き込む
|
17 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix='.csv') as tmp:
|
18 |
+
df.to_csv(tmp.name, index=False)
|
19 |
+
tmp_path = tmp.name
|
20 |
+
|
21 |
+
return tmp_path
|
|
|
22 |
|
23 |
interface = gr.Interface(
|
24 |
fn=double_age,
|
25 |
inputs=gr.File(label="CSVファイルをアップロード"),
|
26 |
+
outputs=gr.File(label="ダウンロード", file_count="singular"),
|
27 |
allow_flagging="never"
|
28 |
)
|
29 |
|