ginipick commited on
Commit
b84e378
·
verified ·
1 Parent(s): f7137c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -17
app.py CHANGED
@@ -944,26 +944,48 @@ def respond(
944
  # 기사 내용 추출
945
  article_content = get_article_content(url)
946
 
947
- # 번역 요청을 위한 프롬프트 구성
948
- translation_prompt = f"""Please translate the following article to Korean.
949
- Maintain the original meaning and context while making it natural in Korean.
950
-
951
- Article: {article_content}
952
-
953
- Korean translation:"""
954
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
955
  messages = [
956
- {"role": "system", "content": system_message or "You are a helpful translator that translates articles to Korean."},
 
 
 
 
 
 
 
957
  {"role": "user", "content": translation_prompt}
958
  ]
959
 
960
- # 사용자 입력을 히스토리에 추가
961
- history.append((url, "번역을 시작합니다..."))
962
 
963
- # 번역 결과를 저장할 변수
964
  full_response = ""
 
965
 
966
- # 스트리밍 응답 처리
967
  for message in client.chat.completions.create(
968
  model="CohereForAI/c4ai-command-r-plus-08-2024",
969
  max_tokens=max_tokens,
@@ -976,12 +998,16 @@ def respond(
976
  token = message.choices[0].delta.content
977
  if token:
978
  full_response += token
979
- # 마지막 메시지를 업데이트
 
 
 
 
980
  history[-1] = (url, full_response)
981
  yield history
982
-
983
  except Exception as e:
984
- error_message = f"번역 중 오류가 발생했습니다: {str(e)}"
985
  history.append((url, error_message))
986
  yield history
987
 
@@ -1106,9 +1132,30 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css, title="NewsAI 서비
1106
 
1107
  with gr.Accordion("고급 설정", open=False):
1108
  system_message = gr.Textbox(
1109
- value="You are a helpful translator that translates articles to Korean accurately and naturally. 1) '번역'을 먼저 출력하라. 2) 이어서 '번역된 내용'에 대해 '뉴스 기사' 형식으로 작성하여 신문 기사 양식으로 출력하라. 반드시 줄 바꾸기등 가독성 있게 출력하여야 하며, '습니다.'.'입니다.'등을 사용하지 말고 '다.'로 끝내야 한다. 철저하게 신문 기사 형식을 전문적인 기자가 작성하는 형식이어야 한다.",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1110
  label="System message"
1111
  )
 
1112
  max_tokens = gr.Slider(
1113
  minimum=1,
1114
  maximum=4000,
 
944
  # 기사 내용 추출
945
  article_content = get_article_content(url)
946
 
947
+ # 2단계 프로세스를 위한 프롬프트 구성
948
+ translation_prompt = f"""다음 작업을 순차적으로 수행하세요:
949
+
950
+ 1단계: 번역
951
+ 아래 영문 기사를 한국어로 정확하게 번역하세요.
952
+ 구분선: ===번역 시작===
953
+ {article_content}
954
+ 구분선: ===번역 끝===
955
+
956
+ 2단계: 기사 작성
957
+ 위의 번역된 내용을 바탕으로 새로운 한국어 기사를 작성하세요.
958
+ 다음 형식을 반드시 준수하세요:
959
+ - 제목: [헤드라인]
960
+ - 부제: [서브헤드라인]
961
+ - 본문: [기사 내용]
962
+ - 작성 규칙:
963
+ * 문장은 '다.'로 끝나야 함
964
+ * 신문 기사 형식 준수
965
+ * 단락 구분을 명확히 할 것
966
+ * 핵심 정보를 앞부분에 배치
967
+ * 인용구는 따옴표로 처리
968
+
969
+ 각 단계는 '===번역===', '===기사==='로 구분하여 출력하세요.
970
+ """
971
+
972
  messages = [
973
+ {
974
+ "role": "system",
975
+ "content": """당신은 전문 번역가이자 기자입니다.
976
+ 모든 작업은 반드시 다음 두 단계로 진행하고, 각 단계를 명확히 구분하여 출력해야 합니다:
977
+ 1. 원문 번역: ===번역=== 표시 후 정확한 한국어 번역 제공
978
+ 2. 기사 작성: ===기사=== 표시 후 번역본을 기반으로 한국어 뉴스 기사 작성
979
+ 두 단계를 건너뛰거나 통합하지 말고 반드시 순차적으로 진행하세요."""
980
+ },
981
  {"role": "user", "content": translation_prompt}
982
  ]
983
 
984
+ history.append((url, "번역 기사 작성을 시작합니다..."))
 
985
 
 
986
  full_response = ""
987
+ current_section = ""
988
 
 
989
  for message in client.chat.completions.create(
990
  model="CohereForAI/c4ai-command-r-plus-08-2024",
991
  max_tokens=max_tokens,
 
998
  token = message.choices[0].delta.content
999
  if token:
1000
  full_response += token
1001
+ # 섹션 구분자 확인 및 포맷팅
1002
+ if "===번역===" in token or "===기사===" in token:
1003
+ current_section = token.strip()
1004
+ full_response += "\n\n"
1005
+
1006
  history[-1] = (url, full_response)
1007
  yield history
1008
+
1009
  except Exception as e:
1010
+ error_message = f"처리 중 오류가 발생했습니다: {str(e)}"
1011
  history.append((url, error_message))
1012
  yield history
1013
 
 
1132
 
1133
  with gr.Accordion("고급 설정", open=False):
1134
  system_message = gr.Textbox(
1135
+ value="""You are a professional translator and journalist. Follow these steps strictly:
1136
+ 1. TRANSLATION
1137
+ - Start with ===번역=== marker
1138
+ - Provide accurate Korean translation
1139
+ - Maintain original meaning and context
1140
+
1141
+ 2. ARTICLE WRITING
1142
+ - Start with ===기사=== marker
1143
+ - Write a new Korean news article based on the translation
1144
+ - Follow newspaper article format
1145
+ - Use formal news writing style
1146
+ - End sentences with '다.'
1147
+ - Include headline and subheadline
1148
+ - Organize paragraphs clearly
1149
+ - Put key information first
1150
+ - Use quotes appropriately
1151
+
1152
+ IMPORTANT:
1153
+ - Must complete both steps in order
1154
+ - Clearly separate each section with markers
1155
+ - Never skip or combine steps""",
1156
  label="System message"
1157
  )
1158
+
1159
  max_tokens = gr.Slider(
1160
  minimum=1,
1161
  maximum=4000,