Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,28 @@
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
-
import io
|
4 |
|
5 |
def double_age(csv_file):
|
6 |
-
#
|
7 |
-
|
8 |
-
df = pd.read_csv(io.StringIO("\n".join(csv_data)))
|
9 |
|
|
|
|
|
|
|
|
|
10 |
df['age'] = df['age'] * 2
|
|
|
|
|
11 |
csv_output = df.to_csv(index=False)
|
|
|
12 |
return csv_output
|
13 |
|
14 |
interface = gr.Interface(
|
15 |
fn=double_age,
|
16 |
inputs=gr.File(label="CSVファイルをアップロード"),
|
17 |
outputs=gr.File(label="ダウンロード"),
|
18 |
-
|
|
|
|
|
19 |
)
|
20 |
|
21 |
interface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
|
|
3 |
|
4 |
def double_age(csv_file):
|
5 |
+
# ファイル名を取得
|
6 |
+
file_name = csv_file.name
|
|
|
7 |
|
8 |
+
# CSVファイルを読み込む
|
9 |
+
df = pd.read_csv(file_name)
|
10 |
+
|
11 |
+
# ageカラムの値を2倍にする
|
12 |
df['age'] = df['age'] * 2
|
13 |
+
|
14 |
+
# 変更したDataFrameをCSVに変換
|
15 |
csv_output = df.to_csv(index=False)
|
16 |
+
|
17 |
return csv_output
|
18 |
|
19 |
interface = gr.Interface(
|
20 |
fn=double_age,
|
21 |
inputs=gr.File(label="CSVファイルをアップロード"),
|
22 |
outputs=gr.File(label="ダウンロード"),
|
23 |
+
examples=[
|
24 |
+
["example_data.csv"] # サンプルデータがあれば指定します
|
25 |
+
]
|
26 |
)
|
27 |
|
28 |
interface.launch()
|