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