Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,30 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
from transformers import pipeline
|
4 |
|
5 |
+
# ChatGPTのパイプラインを初期化(ここでは例としてtext-generationを使用)
|
6 |
+
chatgpt_pipeline = pipeline("text-generation", model="EleutherAI/gpt-neo-2.7B")
|
7 |
|
8 |
+
def process_csv(file_obj):
|
9 |
+
# アップロードされたCSVファイルを読み込む
|
10 |
+
df = pd.read_csv(file_obj)
|
11 |
+
responses = []
|
12 |
+
|
13 |
+
# CSVの各行に対してChatGPTを呼び出し
|
14 |
+
for _, row in df.iterrows():
|
15 |
+
input_text = row['text'] # 'text'カラムを入力として使用
|
16 |
+
response = chatgpt_pipeline(input_text, max_length=50)
|
17 |
+
responses.append([input_text, response[0]['generated_text']])
|
18 |
+
|
19 |
+
# 結果をDataFrameに変換し、CSVファイルとして出力
|
20 |
+
output_df = pd.DataFrame(responses, columns=['Input Text', 'Generated Text'])
|
21 |
+
return output_df.to_csv(index=False)
|
22 |
+
|
23 |
+
# Gradioインターフェースの定義
|
24 |
+
iface = gr.Interface(fn=process_csv,
|
25 |
+
inputs=gr.inputs.File(label="Upload CSV"),
|
26 |
+
outputs="file",
|
27 |
+
description="Upload a CSV, get ChatGPT responses for each row.")
|
28 |
+
|
29 |
+
# アプリの起動
|
30 |
iface.launch()
|