| import os |
| import openai |
| import gradio as gr |
|
|
| |
| 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() |
|
|