Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
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,7 +13,7 @@ def double_age(csv_file):
|
|
13 |
# ageカラムの値を2倍にする
|
14 |
df['age'] = df['age'] * 2
|
15 |
|
16 |
-
|
17 |
with tempfile.NamedTemporaryFile(delete=False, suffix='.csv') as tmp:
|
18 |
df.to_csv(tmp.name, index=False)
|
19 |
tmp_path = tmp.name
|
@@ -22,14 +22,17 @@ def double_age(csv_file):
|
|
22 |
new_path = os.path.join(os.path.dirname(tmp_path), "sample.csv")
|
23 |
os.rename(tmp_path, new_path)
|
24 |
|
25 |
-
return
|
26 |
|
27 |
interface = gr.Interface(
|
28 |
fn=double_age,
|
29 |
inputs=gr.File(label="CSVファイルをアップロード"),
|
30 |
outputs=gr.File(label="ダウンロード", file_count="singular"),
|
31 |
-
allow_flagging="never"
|
32 |
-
|
|
|
|
|
|
|
33 |
cancel_button="キャンセル",
|
34 |
submit_button="実行",
|
35 |
)
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
|
|
3 |
import tempfile
|
4 |
+
import os
|
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
|
|
|
22 |
new_path = os.path.join(os.path.dirname(tmp_path), "sample.csv")
|
23 |
os.rename(tmp_path, new_path)
|
24 |
|
25 |
+
return new_path
|
26 |
|
27 |
interface = gr.Interface(
|
28 |
fn=double_age,
|
29 |
inputs=gr.File(label="CSVファイルをアップロード"),
|
30 |
outputs=gr.File(label="ダウンロード", file_count="singular"),
|
31 |
+
allow_flagging="never",
|
32 |
+
live=True,
|
33 |
+
examples=None,
|
34 |
+
|
35 |
+
# キャンセルと実行のボタン名を変更
|
36 |
cancel_button="キャンセル",
|
37 |
submit_button="実行",
|
38 |
)
|