Spaces:
Running
on
Zero
Running
on
Zero
mimic chinese input method layout style
Browse files
app.py
CHANGED
@@ -38,7 +38,7 @@ 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):
|
@@ -47,16 +47,22 @@ def append_suggestion(current, choice):
|
|
47 |
with gr.Blocks() as demo:
|
48 |
gr.Markdown(
|
49 |
"## 🇹🇼 台灣中文下段預測 \n"
|
50 |
-
"結合小型語言模型與 ZeroGPU
|
51 |
)
|
52 |
|
53 |
-
#
|
|
|
|
|
|
|
|
|
|
|
54 |
with gr.Row():
|
55 |
input_text = gr.TextArea(
|
56 |
label="輸入文字", lines=4, placeholder="請在此輸入起始片段…"
|
57 |
)
|
58 |
gpu_button = gr.Button("使用 GPU 生成建議")
|
59 |
|
|
|
60 |
with gr.Row():
|
61 |
model_selector = gr.Dropdown(
|
62 |
MODEL_LIST, value=MODEL_LIST[0], label="選擇模型"
|
@@ -68,16 +74,12 @@ with gr.Blocks() as demo:
|
|
68 |
minimum=1, maximum=10, step=1, value=5, label="M(建議數量 / Beam 數)"
|
69 |
)
|
70 |
|
71 |
-
#
|
72 |
-
suggestions = gr.Radio([], label="建議清單")
|
73 |
-
|
74 |
-
# 連結生成按鈕到推理函式
|
75 |
gpu_button.click(
|
76 |
fn=suggest_next,
|
77 |
inputs=[input_text, model_selector, k_slider, m_slider],
|
78 |
outputs=suggestions,
|
79 |
)
|
80 |
-
# 點選建議後立刻拼接到文字框
|
81 |
suggestions.change(
|
82 |
fn=append_suggestion,
|
83 |
inputs=[input_text, suggestions],
|
|
|
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):
|
|
|
47 |
with gr.Blocks() as demo:
|
48 |
gr.Markdown(
|
49 |
"## 🇹🇼 台灣中文下段預測 \n"
|
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="選擇模型"
|
|
|
74 |
minimum=1, maximum=10, step=1, value=5, label="M(建議數量 / Beam 數)"
|
75 |
)
|
76 |
|
77 |
+
# 事件綁定
|
|
|
|
|
|
|
78 |
gpu_button.click(
|
79 |
fn=suggest_next,
|
80 |
inputs=[input_text, model_selector, k_slider, m_slider],
|
81 |
outputs=suggestions,
|
82 |
)
|
|
|
83 |
suggestions.change(
|
84 |
fn=append_suggestion,
|
85 |
inputs=[input_text, suggestions],
|