import os import openai import gradio as gr # OpenAI API 클라이언트 설정 openai.api_key = os.getenv("OPENAI_API_KEY") def call_api(content, system_message, max_tokens=150, temperature=0.7, top_p=1.0): response = openai.ChatCompletion.create( model="gpt-4o-mini", messages=[ {"role": "system", "content": system_message}, {"role": "user", "content": content}, ], max_tokens=max_tokens, temperature=temperature, top_p=top_p, ) return response.choices[0].message['content'] def translate_code_to_korean(code): system_message = "You are a helpful assistant that translates English code comments and documentation into Korean without altering the actual code functionality." prompt = f"Please translate the following code comments and documentation from English to Korean:\n\n{code}" translated_code = call_api(prompt, system_message) return translated_code iface = gr.Interface( fn=translate_code_to_korean, inputs=gr.Textbox(lines=10, placeholder="여기에 영어로 된 코드를 입력하세요..."), outputs=gr.Textbox(lines=10, placeholder="번역된 한국어 코드를 여기에 표시합니다."), title="코드 번역기", description="영어로 작성된 코드의 주석과 문서를 한국어로 번역해드립니다.", allow_flagging="never" ) if __name__ == "__main__": iface.launch()