Spaces:
Sleeping
Sleeping
| import os | |
| import openai | |
| import gradio as gr | |
| # ํ๊ฒฝ ๋ณ์์ ์ ์ฅ๋ API ํค ์ฌ์ฉ | |
| openai.api_key = os.getenv("OPENAI_API_KEY") | |
| def call_api(content, system_message, max_tokens=1024, temperature=0.2, top_p=1.0): | |
| """ | |
| gpt-4o-mini ๋ชจ๋ธ์ ์ฌ์ฉ์ ์ ๋ ฅ์ ๋ณด๋ด๊ณ ๋ฒ์ญ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ์์จ๋ค. | |
| """ | |
| 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_english_to_korean(code_text): | |
| """ | |
| ์์ด๋ก ์์ฑ๋ ์ฝ๋๋ ์ค๋ช ์ ์์ฐ์ค๋ฝ๊ฒ ํ๊ตญ์ด๋ก ์ฎ๊ธด๋ค. | |
| """ | |
| system_msg = ( | |
| "You are a professional translator who accurately conveys English code " | |
| "comments and explanations into smooth, natural Korean. Preserve code syntax " | |
| "while ensuring natural readability." | |
| ) | |
| return call_api(code_text, system_msg) | |
| def main(): | |
| """ | |
| Gradio ์ธํฐํ์ด์ค ์คํ | |
| """ | |
| interface = gr.Interface( | |
| fn=translate_english_to_korean, | |
| inputs=gr.Textbox(lines=10, label="์์ด ์ฝ๋ ์ ๋ ฅ"), | |
| outputs=gr.Textbox(lines=10, label="๋ฒ์ญ ๊ฒฐ๊ณผ"), | |
| title="์ฝ๋ ์์ด -> ํ๊ตญ์ด ๋ฒ์ญ๊ธฐ", | |
| description="์์ด๋ก ์์ฑ๋ ์ฝ๋๋ฅผ ์์ฐ์ค๋ฝ๊ฒ ํ๊ตญ์ด๋ก ์ฎ๊ฒจ์ฃผ๋ ๊ฐ๋จํ ๋๊ตฌ์ ๋๋ค." | |
| ) | |
| interface.launch(server_name="0.0.0.0", server_port=7860) | |
| if __name__ == "__main__": | |
| main() | |