Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,12 +2,15 @@ import os
|
|
| 2 |
import openai
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
#
|
| 6 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 7 |
|
| 8 |
-
def call_api(content, system_message, max_tokens=
|
|
|
|
|
|
|
|
|
|
| 9 |
response = openai.ChatCompletion.create(
|
| 10 |
-
model="gpt-4o-mini",
|
| 11 |
messages=[
|
| 12 |
{"role": "system", "content": system_message},
|
| 13 |
{"role": "user", "content": content},
|
|
@@ -18,20 +21,29 @@ def call_api(content, system_message, max_tokens=1000, temperature=0.5, top_p=1.
|
|
| 18 |
)
|
| 19 |
return response.choices[0].message['content']
|
| 20 |
|
| 21 |
-
def
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
if __name__ == "__main__":
|
| 37 |
-
|
|
|
|
| 2 |
import openai
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
+
# ํ๊ฒฝ ๋ณ์์ ์ ์ฅ๋ API ํค ์ฌ์ฉ
|
| 6 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 7 |
|
| 8 |
+
def call_api(content, system_message, max_tokens=1024, temperature=0.2, top_p=1.0):
|
| 9 |
+
"""
|
| 10 |
+
gpt-4o-mini ๋ชจ๋ธ์ ์ฌ์ฉ์ ์
๋ ฅ์ ๋ณด๋ด๊ณ ๋ฒ์ญ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ์์จ๋ค.
|
| 11 |
+
"""
|
| 12 |
response = openai.ChatCompletion.create(
|
| 13 |
+
model="gpt-4o-mini",
|
| 14 |
messages=[
|
| 15 |
{"role": "system", "content": system_message},
|
| 16 |
{"role": "user", "content": content},
|
|
|
|
| 21 |
)
|
| 22 |
return response.choices[0].message['content']
|
| 23 |
|
| 24 |
+
def translate_english_to_korean(code_text):
|
| 25 |
+
"""
|
| 26 |
+
์์ด๋ก ์์ฑ๋ ์ฝ๋๋ ์ค๋ช
์ ์์ฐ์ค๋ฝ๊ฒ ํ๊ตญ์ด๋ก ์ฎ๊ธด๋ค.
|
| 27 |
+
"""
|
| 28 |
+
system_msg = (
|
| 29 |
+
"You are a professional translator who accurately conveys English code "
|
| 30 |
+
"comments and explanations into smooth, natural Korean. Preserve code syntax "
|
| 31 |
+
"while ensuring natural readability."
|
| 32 |
+
)
|
| 33 |
+
return call_api(code_text, system_msg)
|
| 34 |
|
| 35 |
+
def main():
|
| 36 |
+
"""
|
| 37 |
+
Gradio ์ธํฐํ์ด์ค ์คํ
|
| 38 |
+
"""
|
| 39 |
+
interface = gr.Interface(
|
| 40 |
+
fn=translate_english_to_korean,
|
| 41 |
+
inputs=gr.Textbox(lines=10, label="์์ด ์ฝ๋ ์
๋ ฅ"),
|
| 42 |
+
outputs=gr.Textbox(lines=10, label="๋ฒ์ญ ๊ฒฐ๊ณผ"),
|
| 43 |
+
title="์ฝ๋ ์์ด -> ํ๊ตญ์ด ๋ฒ์ญ๊ธฐ",
|
| 44 |
+
description="์์ด๋ก ์์ฑ๋ ์ฝ๋๋ฅผ ์์ฐ์ค๋ฝ๊ฒ ํ๊ตญ์ด๋ก ์ฎ๊ฒจ์ฃผ๋ ๊ฐ๋จํ ๋๊ตฌ์
๋๋ค."
|
| 45 |
+
)
|
| 46 |
+
interface.launch(server_name="0.0.0.0", server_port=7860)
|
| 47 |
|
| 48 |
if __name__ == "__main__":
|
| 49 |
+
main()
|