1234 / app.py
Kims12's picture
Create app.py
448aa83 verified
import os
import openai
import gradio as gr
# OpenAI API ํด๋ผ์ด์–ธํŠธ ์„ค์ •
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()