Kims12 commited on
Commit
c5eb776
·
verified ·
1 Parent(s): 350c1cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -2
app.py CHANGED
@@ -1,6 +1,10 @@
1
  import os
2
  import openai
3
  import gradio as gr
 
 
 
 
4
 
5
  # OpenAI API 키를 환경 변수에서 가져오기
6
  openai.api_key = os.getenv("OPENAI_API_KEY")
@@ -9,7 +13,25 @@ def translate_to_korean(english_text):
9
  """
10
  입력된 영어 텍스트를 한국어로 번역하는 함수
11
  """
12
- system_message = "You are a helpful assistant that translates English text to Korean."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  try:
14
  response = openai.ChatCompletion.create(
15
  model="gpt-4o-mini", # 모델 ID
@@ -29,7 +51,7 @@ def translate_to_korean(english_text):
29
  # Gradio 인터페이스 구성
30
  with gr.Blocks() as iface:
31
  gr.Markdown("# 영어-한국어 번역기")
32
- gr.Markdown("GPT-4o-mini 모델을 사용하여 영어 텍스트를 한국어로 번역합니다.")
33
 
34
  with gr.Row():
35
  with gr.Column():
 
1
  import os
2
  import openai
3
  import gradio as gr
4
+ from dotenv import load_dotenv
5
+
6
+ # 환경 변수 로드
7
+ load_dotenv()
8
 
9
  # OpenAI API 키를 환경 변수에서 가져오기
10
  openai.api_key = os.getenv("OPENAI_API_KEY")
 
13
  """
14
  입력된 영어 텍스트를 한국어로 번역하는 함수
15
  """
16
+ system_message = (
17
+ "You are an assistant that translates English text to Korean. "
18
+ "Ensure that the translation adheres to the following guidelines:\n\n"
19
+ "1. Prioritize natural and fluent Korean over literal translations.\n"
20
+ "2. Maintain grammatical accuracy:\n"
21
+ " - Prefer active voice over passive voice.\n"
22
+ " - Minimize the use of pronouns.\n"
23
+ " - Prefer verbs and adjectives over nominalizations.\n"
24
+ " - Use simple present or present perfect tense instead of present continuous.\n"
25
+ " - Maintain Subject-Object-Verb order.\n"
26
+ " - Avoid using expressions like \"~었어요\".\n"
27
+ "3. Ensure a natural flow that matches the context of the subject.\n"
28
+ "4. Choose vocabulary that is appropriate for the topic and situation.\n"
29
+ "5. Reflect emotional nuances to create empathetic expressions.\n"
30
+ "6. Maintain a balance between literal and free translation.\n"
31
+ "7. Avoid repeating topic keywords.\n"
32
+ "8. Ensure the translation does not appear to be written by AI.\n"
33
+ )
34
+
35
  try:
36
  response = openai.ChatCompletion.create(
37
  model="gpt-4o-mini", # 모델 ID
 
51
  # Gradio 인터페이스 구성
52
  with gr.Blocks() as iface:
53
  gr.Markdown("# 영어-한국어 번역기")
54
+ gr.Markdown("GPT-4o-mini 모델을 사용하여 영어 텍스트를 한국어로 번역합니다. 번역 시 자연스럽고 매끄러운 한국어로 제공됩니다.")
55
 
56
  with gr.Row():
57
  with gr.Column():