import gradio as gr import openai import os openai.api_key = os.getenv("OPENAI_API_KEY") def trans(word): msg = "다음줄의 텍스트에 대해서 한글은 영어로, 영어는 한글로 번역해줘. \n" + word print(msg) chat_completion = openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=[{"role": "user", "content": msg}] ) result = chat_completion["choices"][0]["message"]["content"] return result app = gr.Interface( fn=trans, inputs=[ gr.Textbox(), ], outputs="text", examples=[["ko2en", "사랑"], ["en2ko", "love"]], allow_flagging="manual", ) app.launch(debug=True)