Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,34 @@
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
-
import openai
|
4 |
import tempfile
|
5 |
import os
|
|
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
|
10 |
def process_csv(csv_file):
|
11 |
# CSVファイルを読み込む
|
12 |
df = pd.read_csv(csv_file.name)
|
13 |
|
14 |
-
#
|
15 |
outputs = []
|
16 |
for _, row in df.iterrows():
|
17 |
id = row['id']
|
18 |
input_text = row['input']
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
outputs.append({'id': id, 'output': output_text})
|
27 |
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
|
|
3 |
import tempfile
|
4 |
import os
|
5 |
+
import requests
|
6 |
|
7 |
+
# OpenAI API キーを設定する
|
8 |
+
OPENAI_API_KEY = "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" # ここにあなたのOpenAI API キーを入力してください
|
9 |
|
10 |
def process_csv(csv_file):
|
11 |
# CSVファイルを読み込む
|
12 |
df = pd.read_csv(csv_file.name)
|
13 |
|
14 |
+
# ChatGPT API に入力を送信し、出力を取得
|
15 |
outputs = []
|
16 |
for _, row in df.iterrows():
|
17 |
id = row['id']
|
18 |
input_text = row['input']
|
19 |
|
20 |
+
# ChatGPT API を直接呼び出す
|
21 |
+
headers = {
|
22 |
+
"Content-Type": "application/json",
|
23 |
+
"Authorization": f"Bearer {OPENAI_API_KEY}"
|
24 |
+
}
|
25 |
+
data = {
|
26 |
+
"model": "gpt-3.5-turbo",
|
27 |
+
"messages": [{"role": "user", "content": input_text}]
|
28 |
+
}
|
29 |
+
response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=data)
|
30 |
+
response_json = response.json()
|
31 |
+
output_text = response_json["choices"][0]["message"]["content"]
|
32 |
|
33 |
outputs.append({'id': id, 'output': output_text})
|
34 |
|