Spaces:
Sleeping
Sleeping
File size: 1,646 Bytes
a0a5234 0424bd2 a0a5234 0424bd2 a0a5234 0424bd2 a0a5234 0424bd2 a0a5234 0424bd2 a0a5234 0424bd2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | 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()
|