Files changed (1) hide show
  1. app.py +24 -6
app.py CHANGED
@@ -1,8 +1,12 @@
1
  import gradio as gr
2
  import pandas as pd
3
  import json
 
4
 
5
- def excel_to_json(file):
 
 
 
6
  # エクセルファイルを読み込み
7
  df = pd.read_excel(file)
8
 
@@ -12,17 +16,31 @@ def excel_to_json(file):
12
  # JSON形式に変換
13
  json_result = json.dumps(column_values, ensure_ascii=False, indent=2)
14
 
15
- return json_result
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  # Gradioインターフェースの設定
18
  interface = gr.Interface(
19
- fn=excel_to_json,
20
  inputs=gr.File(label="Upload Excel File"),
21
- outputs=gr.Textbox(label="JSON Output"),
22
- title="Excel to JSON Converter",
23
- description="Upload an Excel file and get JSON output of column C values from the second row onward."
24
  )
25
 
26
  # Gradioアプリの実行
27
  interface.launch()
28
 
 
 
1
  import gradio as gr
2
  import pandas as pd
3
  import json
4
+ import openai
5
 
6
+ # OpenAI APIキーを設定(あなたのAPIキーをここに入力してください)
7
+ openai.api_key = 'sk-proj-O9Qlw9lhCqMrWx4TNtLCT3BlbkFJDqrx6zKPfAv3ljoutKhi'
8
+
9
+ def excel_to_json_and_convert(file):
10
  # エクセルファイルを読み込み
11
  df = pd.read_excel(file)
12
 
 
16
  # JSON形式に変換
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.Completion.create(
24
+ engine="gpt-4o",
25
+ prompt=prompt,
26
+ max_tokens=500
27
+ )
28
+
29
+ # レスポンスからテキストを抽出
30
+ converted_text = response.choices[0].text.strip()
31
+
32
+ return converted_text
33
 
34
  # Gradioインターフェースの設定
35
  interface = gr.Interface(
36
+ fn=excel_to_json_and_convert,
37
  inputs=gr.File(label="Upload Excel File"),
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アプリの実行
44
  interface.launch()
45
 
46
+