Spaces:
Sleeping
Sleeping
File size: 1,456 Bytes
8b13cc0 a0e1209 8b13cc0 a0e1209 8b13cc0 a0e1209 8b13cc0 a0e1209 5d59983 a0e1209 8b13cc0 37ecefa a0e1209 | 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 | 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):
# エクセルファイルを読み込み
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.Completion.create(
engine="gpt-4o",
prompt=prompt,
max_tokens=500
)
# レスポンスからテキストを抽出
converted_text = response.choices[0].text.strip()
return converted_text
# Gradioインターフェースの設定
interface = gr.Interface(
fn=excel_to_json_and_convert,
inputs=gr.File(label="Upload Excel File"),
outputs=gr.Textbox(label="Converted Output"),
title="Excel to JSON Converter and OpenAI GPT-3 Converter",
description="Upload an Excel file and get JSON output of column C values converted to half-width Katakana by OpenAI GPT-3."
)
# Gradioアプリの実行
interface.launch()
|