import gradio as gr import os import openai openai.api_key = os.getenv("OPENAI_API_KEY") def trans(type, word): msg = '아래 내용을 한국어에서 영어로 번역해줘\n' if(type == 'en2ko') : msg = '아래 내용을 영어에서 한국어로 번역해줘\n' msg = msg + word chat_completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[{"role": "user", "content": msg}]) return chat_completion.choices[0].message.content app = gr.Interface( fn=trans, inputs=[ gr.Radio(['ko2en', 'en2ko']), gr.Textbox(placeholder="한국어") ], outputs="text" ) app.launch(debug=True)