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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -20
app.py CHANGED
@@ -1,24 +1,15 @@
1
  import gradio as gr
2
  import pandas as pd
3
- import tempfile
4
- import os
5
-
6
- def process_csv(file_obj):
7
- df = pd.read_csv(file_obj)
8
- df['age'] = df['age'] * 2
9
-
10
- # 一時ファイルを作成して結果を書き込む
11
- with tempfile.NamedTemporaryFile(delete=False, suffix='.csv', mode='w+') as tmp_file:
12
- df.to_csv(tmp_file.name, index=False)
13
- # 一時ファイルのパスを保持
14
- temp_file_path = tmp_file.name
15
-
16
- # 一時ファイルのパスを返却
17
- return temp_file_path
18
-
19
- iface = gr.Interface(fn=process_csv,
20
- inputs=gr.File(label="Upload CSV"),
21
- outputs=gr.File(label="Download Processed CSV", type="file"), # 'type'を'file'に設定
22
- description="Upload a CSV with 'name' and 'age' columns. This app will double the 'age' and let you download the processed CSV.")
23
 
24
  iface.launch()
 
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()