Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,9 +4,9 @@ import json
|
|
| 4 |
import openai
|
| 5 |
|
| 6 |
# OpenAI APIキーを設定(あなたのAPIキーをここに入力してください)
|
| 7 |
-
openai.api_key = '
|
| 8 |
|
| 9 |
-
def excel_to_json_and_convert(file):
|
| 10 |
# エクセルファイルを読み込み
|
| 11 |
df = pd.read_excel(file)
|
| 12 |
|
|
@@ -17,27 +17,32 @@ def excel_to_json_and_convert(file):
|
|
| 17 |
json_result = json.dumps(column_values, ensure_ascii=False, indent=2)
|
| 18 |
|
| 19 |
# OpenAIのAPIに送信するプロンプトを作成
|
| 20 |
-
prompt = "次の内容を半角カタカ
|
| 21 |
|
| 22 |
# OpenAI GPT-3にリクエストを送信
|
| 23 |
-
response = openai.
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
| 27 |
)
|
| 28 |
|
| 29 |
# レスポンスからテキストを抽出
|
| 30 |
-
converted_text = response
|
| 31 |
|
| 32 |
return converted_text
|
| 33 |
|
| 34 |
# Gradioインターフェースの設定
|
| 35 |
interface = gr.Interface(
|
| 36 |
fn=excel_to_json_and_convert,
|
| 37 |
-
inputs=
|
|
|
|
|
|
|
|
|
|
| 38 |
outputs=gr.Textbox(label="Converted Output"),
|
| 39 |
-
title="Excel to JSON Converter and OpenAI GPT-3 Converter",
|
| 40 |
-
description="Upload an Excel file and get JSON output of column C values converted to half-width Katakana by OpenAI GPT-3."
|
| 41 |
)
|
| 42 |
|
| 43 |
# Gradioアプリの実行
|
|
|
|
| 4 |
import openai
|
| 5 |
|
| 6 |
# OpenAI APIキーを設定(あなたのAPIキーをここに入力してください)
|
| 7 |
+
openai.api_key = 'your_openai_api_key'
|
| 8 |
|
| 9 |
+
def excel_to_json_and_convert(file, engine):
|
| 10 |
# エクセルファイルを読み込み
|
| 11 |
df = pd.read_excel(file)
|
| 12 |
|
|
|
|
| 17 |
json_result = json.dumps(column_values, ensure_ascii=False, indent=2)
|
| 18 |
|
| 19 |
# OpenAIのAPIに送信するプロンプトを作成
|
| 20 |
+
prompt = "次の内容を半角カタカナに変換してください:\n" + json_result
|
| 21 |
|
| 22 |
# OpenAI GPT-3にリクエストを送信
|
| 23 |
+
response = openai.ChatCompletion.create(
|
| 24 |
+
model=engine,
|
| 25 |
+
messages=[
|
| 26 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
| 27 |
+
{"role": "user", "content": prompt}
|
| 28 |
+
]
|
| 29 |
)
|
| 30 |
|
| 31 |
# レスポンスからテキストを抽出
|
| 32 |
+
converted_text = response['choices'][0]['message']['content'].strip()
|
| 33 |
|
| 34 |
return converted_text
|
| 35 |
|
| 36 |
# Gradioインターフェースの設定
|
| 37 |
interface = gr.Interface(
|
| 38 |
fn=excel_to_json_and_convert,
|
| 39 |
+
inputs=[
|
| 40 |
+
gr.File(label="Upload Excel File"),
|
| 41 |
+
gr.Radio(choices=["gpt-3.5-turbo", "gpt-4"], label="Select OpenAI Model")
|
| 42 |
+
],
|
| 43 |
outputs=gr.Textbox(label="Converted Output"),
|
| 44 |
+
title="Excel to JSON Converter and OpenAI GPT-3/4 Converter",
|
| 45 |
+
description="Upload an Excel file and get JSON output of column C values converted to half-width Katakana by OpenAI GPT-3/4."
|
| 46 |
)
|
| 47 |
|
| 48 |
# Gradioアプリの実行
|