Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import openai
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
# OpenAI API ํด๋ผ์ด์ธํธ ์ค์
|
| 6 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 7 |
+
|
| 8 |
+
def call_api(content, system_message, max_tokens=1000, temperature=0.5, top_p=1.0):
|
| 9 |
+
response = openai.ChatCompletion.create(
|
| 10 |
+
model="gpt-4o-mini", # ๋๋ ๋ค๋ฅธ ๋ชจ๋ธ ID ์ฌ์ฉ
|
| 11 |
+
messages=[
|
| 12 |
+
{"role": "system", "content": system_message},
|
| 13 |
+
{"role": "user", "content": content},
|
| 14 |
+
],
|
| 15 |
+
max_tokens=max_tokens,
|
| 16 |
+
temperature=temperature,
|
| 17 |
+
top_p=top_p,
|
| 18 |
+
)
|
| 19 |
+
return response.choices[0].message['content']
|
| 20 |
+
|
| 21 |
+
def translate_code(english_code):
|
| 22 |
+
system_message = "You are a helpful assistant that translates code comments and documentation from English to Korean."
|
| 23 |
+
user_content = f"Please translate the following code from English to Korean:\n\n{english_code}"
|
| 24 |
+
korean_translation = call_api(user_content, system_message)
|
| 25 |
+
return korean_translation
|
| 26 |
+
|
| 27 |
+
# Gradio ์ธํฐํ์ด์ค ์ค์
|
| 28 |
+
iface = gr.Interface(
|
| 29 |
+
fn=translate_code,
|
| 30 |
+
inputs=gr.inputs.Textbox(lines=20, placeholder="๋ฒ์ญํ ์์ด ์ฝ๋๋ฅผ ์ฌ๊ธฐ์ ์
๋ ฅํ์ธ์."),
|
| 31 |
+
outputs=gr.outputs.Textbox(),
|
| 32 |
+
title="์ฝ๋ ์์ด-ํ๊ตญ์ด ๋ฒ์ญ๊ธฐ",
|
| 33 |
+
description="์์ด๋ก ์์ฑ๋ ์ฝ๋๋ฅผ ํ๊ตญ์ด๋ก ๋ฒ์ญํฉ๋๋ค. ๋ฒ์ญํ ์ฝ๋๋ฅผ ์
๋ ฅํ๊ณ ๋ฒ์ญ ๋ฒํผ์ ํด๋ฆญํ์ธ์."
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
if __name__ == "__main__":
|
| 37 |
+
iface.launch()
|