Luigi commited on
Commit
3941dc3
·
1 Parent(s): 99ef6df

update layout

Browse files
Files changed (1) hide show
  1. app.py +12 -10
app.py CHANGED
@@ -26,7 +26,7 @@ def get_pipeline(model_name):
26
  @spaces.GPU
27
  def suggest_next(text, model_name, k, m):
28
  """
29
- 使用 Beam Search 產生 M 條最可能的下段建議,並一次更新可選項清單。
30
  """
31
  gen_pipe = get_pipeline(model_name)
32
  outs = gen_pipe(
@@ -38,11 +38,10 @@ def suggest_next(text, model_name, k, m):
38
  early_stopping=True
39
  )
40
  suggestions = [out["generated_text"][len(text):] for out in outs]
41
- # 使用 None 重置選值,避免預設 value 不在 choices 列表中
42
  return update(choices=suggestions, value=None)
43
 
44
  def append_suggestion(current, choice):
45
- # 如果沒有選擇,直接返回原文字
46
  if choice is None:
47
  return current
48
  return current + choice
@@ -53,17 +52,20 @@ with gr.Blocks() as demo:
53
  "結合小型語言模型與 ZeroGPU,即時 IME 風格建議條。"
54
  )
55
 
56
- # 建議清單置頂,使用 Radio 類型一次展開
57
  suggestions = gr.Radio(
58
  [], label="建議清單", interactive=True, type="value", elem_id="suggestions-bar"
59
  )
60
 
61
- # 輸入區與生成按鈕並排
62
  with gr.Row():
63
- input_text = gr.TextArea(
64
- label="輸入文字", lines=4, placeholder="請在此輸入起始片段…"
65
- )
66
- gpu_button = gr.Button("使用 GPU 生成建議")
 
 
 
67
 
68
  # 參數設定區
69
  with gr.Row():
@@ -74,7 +76,7 @@ with gr.Blocks() as demo:
74
  minimum=1, maximum=50, step=1, value=5, label="K(最大新生成詞元)"
75
  )
76
  m_slider = gr.Slider(
77
- minimum=1, maximum=10, step=1, value=10, label="M(建議數量 / Beam 數)"
78
  )
79
 
80
  # 事件綁定
 
26
  @spaces.GPU
27
  def suggest_next(text, model_name, k, m):
28
  """
29
+ 使用 Beam Search 產生 M 條最可能的下段建議,並一次更新選項清單。
30
  """
31
  gen_pipe = get_pipeline(model_name)
32
  outs = gen_pipe(
 
38
  early_stopping=True
39
  )
40
  suggestions = [out["generated_text"][len(text):] for out in outs]
41
+ # 重置選值並更新選項
42
  return update(choices=suggestions, value=None)
43
 
44
  def append_suggestion(current, choice):
 
45
  if choice is None:
46
  return current
47
  return current + choice
 
52
  "結合小型語言模型與 ZeroGPU,即時 IME 風格建議條。"
53
  )
54
 
55
+ # 建議清單置頂,模仿輸入法候選欄
56
  suggestions = gr.Radio(
57
  [], label="建議清單", interactive=True, type="value", elem_id="suggestions-bar"
58
  )
59
 
60
+ # 輸入區與生成按鈕並排:加長文字框,按鈕縮小置右側
61
  with gr.Row():
62
+ with gr.Column(scale=5):
63
+ input_text = gr.TextArea(
64
+ label="輸入文字", lines=6,
65
+ placeholder="請在此輸入起始片段…"
66
+ )
67
+ with gr.Column(scale=1, min_width=80):
68
+ gpu_button = gr.Button("使用 GPU 生成建議")
69
 
70
  # 參數設定區
71
  with gr.Row():
 
76
  minimum=1, maximum=50, step=1, value=5, label="K(最大新生成詞元)"
77
  )
78
  m_slider = gr.Slider(
79
+ minimum=1, maximum=10, step=1, value=5, label="M(建議數量 / Beam 數)"
80
  )
81
 
82
  # 事件綁定