File size: 1,239 Bytes
e869a84
3c061e2
e869a84
 
7d70ab6
0234005
8b0e105
7d70ab6
e869a84
 
 
 
 
 
7d70ab6
e869a84
 
7d70ab6
e869a84
7d70ab6
e869a84
7d70ab6
7011a63
b861dc0
7d70ab6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8b0e105
 
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
import openai
import gradio as gr
import os

# OpenAI APIキーを取得
api_key = os.getenv("OPENAI_API_KEY")
if api_key is None:
    raise ValueError("ERROR: OpenAI APIキーが設定されていません。")

client = openai.OpenAI(api_key=api_key)

def chat_with_model(user_input):
    try:
        response = client.chat.completions.create(
            model="ft:gpt-4o-mini-2024-07-18:personal:enjphsr:AukEoAFZ",  
            messages=[{"role": "user", "content": user_input}]
        )
        return response.choices[0].message.content
    except Exception as e:
        return f"エラーが発生しました: {e}"

# 事前入力するテキスト(変更可能)
default_text = "以下の英語を日本語に翻訳してください"

# カスタムCSSを追加
custom_css = """
body {
    overflow: auto !important;
}
.gradio-container {
    max-height: 100vh;
    overflow-y: auto;
}
"""

interface = gr.Interface(
    fn=chat_with_model,
    inputs=gr.Textbox(lines=5, value=default_text),  
    outputs=gr.Textbox(lines=10, interactive=True),  
    title="英→日 スタレ翻訳bot",
    description="ver3.0までのテキストを学習済み",
    css=custom_css  # カスタムCSSを適用
)

interface.launch()