Shiningknob721 commited on
Commit
a6a4918
·
verified ·
1 Parent(s): db25d60

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -1,14 +1,18 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
 
4
  tsundere_ai = pipeline(
5
  "text-generation",
6
  model="rinna/japanese-gpt-neox-3.6b-instruction-ppo",
7
- device_map=None,
8
- tokenizer_kwargs={"use_fast": False}
9
  )
10
 
11
  def convert(text):
 
 
 
12
  prompt = f"""
13
  以下の文章を自然でなめらかなツンデレ口調に変換してください。
14
  ・不自然な語尾にしない
@@ -20,9 +24,11 @@ def convert(text):
20
 
21
  【変換後】"""
22
 
23
- out = tsundere_ai(prompt, max_new_tokens=80, temperature=0.8)[0]["generated_text"]
 
24
  return out.split("【変換後】")[-1].strip()
25
 
 
26
  app = gr.Interface(
27
  fn=convert,
28
  inputs=gr.Textbox(label="入力文"),
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # モデル読み込み(起動時に一度だけ)
5
  tsundere_ai = pipeline(
6
  "text-generation",
7
  model="rinna/japanese-gpt-neox-3.6b-instruction-ppo",
8
+ device_map=None, # CPUのみ
9
+ tokenizer_kwargs={"use_fast": False} # slow tokenizer
10
  )
11
 
12
  def convert(text):
13
+ # 入力文が長すぎる場合は切り詰める
14
+ text = text[:200] # 先頭200文字だけ処理
15
+
16
  prompt = f"""
17
  以下の文章を自然でなめらかなツンデレ口調に変換してください。
18
  ・不自然な語尾にしない
 
24
 
25
  【変換後】"""
26
 
27
+ # max_new_tokens を短めに
28
+ out = tsundere_ai(prompt, max_new_tokens=50, temperature=0.8)[0]["generated_text"]
29
  return out.split("【変換後】")[-1].strip()
30
 
31
+ # Gradio UI
32
  app = gr.Interface(
33
  fn=convert,
34
  inputs=gr.Textbox(label="入力文"),