Luigi commited on
Commit
f4fd3fb
·
1 Parent(s): 60c960b
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -38,10 +38,13 @@ 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
- # 更新 Radio choices,不預設選中任何項
42
- return update(choices=suggestions, value=None)
43
 
44
  def append_suggestion(current, choice):
 
 
 
45
  return current + choice
46
 
47
  with gr.Blocks() as demo:
@@ -50,19 +53,19 @@ with gr.Blocks() as demo:
50
  "結合小型語言模型與 ZeroGPU,即時 IME 風格建議條。"
51
  )
52
 
53
- # 欄位一:建議清單,置頂模仿輸入法建議欄
54
  suggestions = gr.Radio(
55
  [], label="建議清單", interactive=True, type="value", elem_id="suggestions-bar"
56
  )
57
 
58
- # 欄位二:輸入區及生成按鈕,同層排版
59
  with gr.Row():
60
  input_text = gr.TextArea(
61
  label="輸入文字", lines=4, placeholder="請在此輸入起始片段…"
62
  )
63
  gpu_button = gr.Button("使用 GPU 生成建議")
64
 
65
- # 欄位三:模型與參數設定
66
  with gr.Row():
67
  model_selector = gr.Dropdown(
68
  MODEL_LIST, value=MODEL_LIST[0], label="選擇模型"
 
38
  early_stopping=True
39
  )
40
  suggestions = [out["generated_text"][len(text):] for out in outs]
41
+ # 保證 choices 與 value 為空字串而非 None
42
+ return update(choices=suggestions, value="")
43
 
44
  def append_suggestion(current, choice):
45
+ # 防止 None 導致的拼接錯誤
46
+ if not choice:
47
+ return current
48
  return current + choice
49
 
50
  with gr.Blocks() as demo:
 
53
  "結合小型語言模型與 ZeroGPU,即時 IME 風格建議條。"
54
  )
55
 
56
+ # 建議清單置頂
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():
70
  model_selector = gr.Dropdown(
71
  MODEL_LIST, value=MODEL_LIST[0], label="選擇模型"