yeelou commited on
Commit
a979864
·
1 Parent(s): 460899a

add Chinese

Browse files
Files changed (2) hide show
  1. app.py +11 -5
  2. prompts.py +4 -4
app.py CHANGED
@@ -22,6 +22,9 @@ from prompts import TRANS_Prompt, TRANS_Prompt_template
22
  knowledge_cls = knowledge_class()
23
 
24
 
 
 
 
25
  def update_knowledge():
26
  knowledge_cls.get_new_knowledge()
27
  choices_list = list(knowledge_cls.reference_dict.keys())
@@ -46,10 +49,13 @@ def answer_question(
46
  if not answer_text:
47
  yield history
48
  return
49
- if language_flag:
50
  info_title = info_title + f"日本語返信:\n {answer_text}\n"
51
- user_prompt = TRANS_Prompt_template.format(japanese_text=answer_text)
52
- answer_text = generate_item(user_prompt, TRANS_Prompt)
 
 
 
53
 
54
  # text
55
  history.append({"role": "assistant", "content": ""})
@@ -150,8 +156,8 @@ with gr.Blocks(title="勉強会", css=custom_css, head=custom_head, js=js_func)
150
  label="返信スタイル",
151
  )
152
  language_toggle = gr.Radio(
153
- [("English", True), ("日本語", False)],
154
- value=False,
155
  label="言語スタイル",
156
  )
157
  with gr.Accordion("話者紹介", open=False):
 
22
  knowledge_cls = knowledge_class()
23
 
24
 
25
+ language_dict = {"en": "English", "cn": "Chinese"}
26
+
27
+
28
  def update_knowledge():
29
  knowledge_cls.get_new_knowledge()
30
  choices_list = list(knowledge_cls.reference_dict.keys())
 
49
  if not answer_text:
50
  yield history
51
  return
52
+ if language_flag not in ["jp"]:
53
  info_title = info_title + f"日本語返信:\n {answer_text}\n"
54
+ sys_prompt = TRANS_Prompt.format(lang=language_dict[language_flag])
55
+ user_prompt = TRANS_Prompt_template.format(
56
+ japanese_text=answer_text, lang=language_dict[language_flag]
57
+ )
58
+ answer_text = generate_item(user_prompt, sys_prompt)
59
 
60
  # text
61
  history.append({"role": "assistant", "content": ""})
 
156
  label="返信スタイル",
157
  )
158
  language_toggle = gr.Radio(
159
+ [("日本語", "jp"), ("中文", "cn"), ("English", "en")],
160
+ value="jp",
161
  label="言語スタイル",
162
  )
163
  with gr.Accordion("話者紹介", open=False):
prompts.py CHANGED
@@ -3,8 +3,8 @@ You are a specialist in linguistic analysis, skilled at identifying, emulating,
3
  """
4
 
5
  TRANS_Prompt = """
6
- You are a skilled Japanese-to-English translator specializing in conversational text.
7
- Translate the following Japanese dialogue into natural, fluent English, preserving the original tone, personality, and level of formality of each speaker.
8
  """
9
 
10
  SUMMARY_Prompt = """
@@ -19,8 +19,8 @@ Present your analysis in Japanese.
19
  """
20
 
21
  TRANS_Prompt_template = """
22
- Ensure the English reads like real dialogue, suitable for a script, subtitle, or chat. Do not include explanations or the original Japanese.
23
- Only output the English translation. Do not include the original Japanese text, any explanations, notes, or formatting.
24
  Japanese text:
25
  {japanese_text}
26
  """
 
3
  """
4
 
5
  TRANS_Prompt = """
6
+ You are a skilled Japanese-to-{lang} translator specializing in conversational text.
7
+ Translate the following Japanese dialogue into natural, fluent {lang}, preserving the original tone, personality, and level of formality of each speaker.
8
  """
9
 
10
  SUMMARY_Prompt = """
 
19
  """
20
 
21
  TRANS_Prompt_template = """
22
+ Ensure the {lang} reads like real dialogue, suitable for a script, subtitle, or chat. Do not include explanations or the original Japanese.
23
+ Only output the {lang} translation. Do not include the original Japanese text, any explanations, notes, or formatting.
24
  Japanese text:
25
  {japanese_text}
26
  """