sadzxctv commited on
Commit
8cc1975
1 Parent(s): 906dbc9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -8
app.py CHANGED
@@ -8,22 +8,26 @@ from llama_cpp_agent.chat_history import BasicChatHistory
8
  from llama_cpp_agent.chat_history.messages import Roles
9
  import gradio as gr
10
  from huggingface_hub import hf_hub_download
 
11
  repoId = "SakuraLLM/Sakura-14B-Qwen2beta-v0.9.2-GGUF"
12
  filename = "sakura-14b-qwen2beta-v0.9.2-q6k.gguf"
13
- # 下載Sakura-14B模型
 
14
  hf_hub_download(
15
  repo_id=repoId,
16
  filename=filename,
17
  local_dir="./models"
18
  )
 
19
  llm = None
20
  llm_model = None
 
21
  @spaces.GPU(duration=120)
22
  def respond(
23
  message,
24
  history: list[tuple[str, str]],
25
  model=filename,
26
- system_message="你是一个轻小说翻译模型,可以流畅通顺地使用给定的术语表以日本轻小说的风格将日文翻译成简体中文,并联系上下文正确使用人称代词,注意不要混淆使役态和被动态的主语和宾语,不要擅自添加原文中没有的代词,也不要擅自增加或减少换行。",
27
  max_tokens=4096,
28
  temperature=0.1,
29
  top_p=0.3,
@@ -43,6 +47,7 @@ def respond(
43
  n_ctx=8192,
44
  )
45
  llm_model = model
 
46
  provider = LlamaCppPythonProvider(llm)
47
  agent = LlamaCppAgent(
48
  provider,
@@ -52,10 +57,9 @@ def respond(
52
  )
53
 
54
  settings = provider.get_provider_default_settings()
55
- settings.temperature = 0.1
56
- settings.top_k = 0.9
57
- #settings.top_p = top_p
58
- #settings.max_tokens = max_tokens
59
  settings.repeat_penalty = repeat_penalty
60
  settings.stream = True
61
  messages = BasicChatHistory()
@@ -63,7 +67,7 @@ def respond(
63
  for msn in history:
64
  user = {
65
  'role': Roles.user,
66
- 'content': "根据以下术语表(可以为空):\n"+"将下面的日文文本根据上述术语表的对应关系和备注翻译成中文,并且列印出使用哪些术语表:"+msn[0]
67
  }
68
  assistant = {
69
  'role': Roles.assistant,
@@ -85,6 +89,7 @@ def respond(
85
  outputs += output
86
  print(outputs)
87
 
 
88
  # 檢查字串 '你是一个轻小说翻译模型' 是否在 outputs 中
89
  if '你是一个轻小说翻译模型' in outputs:
90
  a = outputs.index('你是一个轻小说翻译模型')
@@ -109,6 +114,7 @@ description = """<p align="center">Defaults to Sakura-14B-Qwen2beta</p>
109
  <a href="https://huggingface.co/SakuraLLM/Sakura-14B-Qwen2beta-v0.9.2-GGUF" target="_blank">[Sakura-14B-Qwen2beta Model]</a>
110
  </center></p>
111
  """
 
112
  demo = gr.ChatInterface(
113
  respond,
114
  retry_btn="Retry",
@@ -123,6 +129,6 @@ demo = gr.ChatInterface(
123
  show_copy_button=True
124
  )
125
  )
 
126
  if __name__ == "__main__":
127
  demo.launch()
128
-
 
8
  from llama_cpp_agent.chat_history.messages import Roles
9
  import gradio as gr
10
  from huggingface_hub import hf_hub_download
11
+
12
  repoId = "SakuraLLM/Sakura-14B-Qwen2beta-v0.9.2-GGUF"
13
  filename = "sakura-14b-qwen2beta-v0.9.2-q6k.gguf"
14
+
15
+ # 下載 Sakura-14B 模型
16
  hf_hub_download(
17
  repo_id=repoId,
18
  filename=filename,
19
  local_dir="./models"
20
  )
21
+
22
  llm = None
23
  llm_model = None
24
+
25
  @spaces.GPU(duration=120)
26
  def respond(
27
  message,
28
  history: list[tuple[str, str]],
29
  model=filename,
30
+ system_message="你是一個專業的翻譯模型,能夠將日文翻譯成流暢的中文,並保持語境一致。",
31
  max_tokens=4096,
32
  temperature=0.1,
33
  top_p=0.3,
 
47
  n_ctx=8192,
48
  )
49
  llm_model = model
50
+
51
  provider = LlamaCppPythonProvider(llm)
52
  agent = LlamaCppAgent(
53
  provider,
 
57
  )
58
 
59
  settings = provider.get_provider_default_settings()
60
+ settings.temperature = temperature
61
+ settings.top_k = top_k
62
+ settings.top_p = top_p
 
63
  settings.repeat_penalty = repeat_penalty
64
  settings.stream = True
65
  messages = BasicChatHistory()
 
67
  for msn in history:
68
  user = {
69
  'role': Roles.user,
70
+ 'content': "請將以下日文文本翻譯成中文:\n" + msn[0]
71
  }
72
  assistant = {
73
  'role': Roles.assistant,
 
89
  outputs += output
90
  print(outputs)
91
 
92
+ # 如果需要進行特定字串的移除或替換,可以在這裡調整
93
  # 檢查字串 '你是一个轻小说翻译模型' 是否在 outputs 中
94
  if '你是一个轻小说翻译模型' in outputs:
95
  a = outputs.index('你是一个轻小说翻译模型')
 
114
  <a href="https://huggingface.co/SakuraLLM/Sakura-14B-Qwen2beta-v0.9.2-GGUF" target="_blank">[Sakura-14B-Qwen2beta Model]</a>
115
  </center></p>
116
  """
117
+
118
  demo = gr.ChatInterface(
119
  respond,
120
  retry_btn="Retry",
 
129
  show_copy_button=True
130
  )
131
  )
132
+
133
  if __name__ == "__main__":
134
  demo.launch()