yosuke-i commited on
Commit
d8d00f5
1 Parent(s): 234d720

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -10
app.py CHANGED
@@ -1,15 +1,19 @@
1
  import gradio as gr
2
  import pandas as pd
3
- def double_age(dataframe):
4
- # 'age'列を2倍にする
5
- dataframe['age'] = dataframe['age'] * 2
6
- # 結果をCSV形式で返す
7
- return dataframe.to_csv(index=False)
8
- iface = gr.Interface(
 
 
9
  fn=double_age,
10
- inputs=gr.Dataframe(headers=["name", "age"], datatype=["str", "number"], row_count=5, col_count=(2, "fixed")),
11
- outputs="text",
12
- description="Upload a CSV file with 'name' and 'age' columns, and download the modified CSV file with 'age' doubled."
 
 
13
  )
14
 
15
- iface.launch()
 
1
  import gradio as gr
2
  import pandas as pd
3
+
4
+ def double_age(csv_file):
5
+ df = pd.read_csv(csv_file.name)
6
+ df['age'] = df['age'] * 2
7
+ csv_data = df.to_csv(index=False)
8
+ return csv_data
9
+
10
+ interface = gr.Interface(
11
  fn=double_age,
12
+ inputs=gr.File(label="CSVファイルをアップロード"),
13
+ outputs=gr.File(label="ダウンロード"),
14
+ examples=[
15
+ ["example_data.csv"] # サンプルデータがあれば指定します
16
+ ]
17
  )
18
 
19
+ interface.launch()