Luigi commited on
Commit
109cc2f
·
1 Parent(s): 6bcfde9

update layout

Browse files
Files changed (1) hide show
  1. app.py +28 -16
app.py CHANGED
@@ -63,6 +63,7 @@ def append_suggestion(current, choice):
63
  # 自訂 CSS:模擬經典中文輸入法候選欄樣式
64
  custom_css = """
65
  #suggestions-bar {
 
66
  margin-bottom: 8px;
67
  }
68
  #suggestions-bar .candidate-list {
@@ -91,29 +92,38 @@ custom_css = """
91
  background: #e6f7ff;
92
  border: 1px solid #1890ff;
93
  }
 
 
 
94
  """
95
 
96
  with gr.Blocks(css=custom_css) as demo:
 
97
  gr.Markdown(
98
  "## 🇹🇼 繁體中文 IME 加速器 \
99
  "
100
  "結合小型語言模型與 ZeroGPU,提供即時輸入法風格候選欄。"
101
  )
102
 
103
- # 候選條(置於上方)
104
- suggestions = gr.Radio(
105
- [], label="", interactive=True, type="value",
106
- elem_id="suggestions-bar", elem_classes="candidate-list"
107
- )
108
-
109
- # 輸入框(置於候選條下方)
110
- input_text = gr.Textbox(
111
- label="", placeholder="請輸入拼音或文字…",
112
- lines=1, max_lines=1, elem_id="input-box"
113
- )
114
 
115
- # 預測按鈕(置於文字框下方)
116
- predict_button = gr.Button("預測", elem_id="predict-button")
 
 
 
 
 
 
117
 
118
  # 進階參數設定(可摺疊)
119
  with gr.Accordion("進階設定", open=False):
@@ -126,11 +136,13 @@ with gr.Blocks(css=custom_css) as demo:
126
  m_slider = gr.Slider(
127
  minimum=1, maximum=30, step=1, value=6, label="M(建議數/Beam 數)"
128
  )
129
- auto_predict = gr.Checkbox(
130
- value=True, label="自動預測(內容變更時觸發)", elem_id="auto-predict"
131
- )
132
 
133
  # 事件綁定
 
 
 
 
 
134
  predict_button.click(
135
  fn=suggest_next,
136
  inputs=[input_text, model_selector, k_slider, m_slider],
 
63
  # 自訂 CSS:模擬經典中文輸入法候選欄樣式
64
  custom_css = """
65
  #suggestions-bar {
66
+ width: 100%;
67
  margin-bottom: 8px;
68
  }
69
  #suggestions-bar .candidate-list {
 
92
  background: #e6f7ff;
93
  border: 1px solid #1890ff;
94
  }
95
+ #input-box {
96
+ width: 100%;
97
+ }
98
  """
99
 
100
  with gr.Blocks(css=custom_css) as demo:
101
+ # 標題與說明
102
  gr.Markdown(
103
  "## 🇹🇼 繁體中文 IME 加速器 \
104
  "
105
  "結合小型語言模型與 ZeroGPU,提供即時輸入法風格候選欄。"
106
  )
107
 
108
+ # 垂直排列:候選欄置於上方,輸入框置於下方
109
+ with gr.Column():
110
+ suggestions = gr.Radio(
111
+ [], label="", interactive=True, type="value",
112
+ elem_id="suggestions-bar", elem_classes="candidate-list"
113
+ )
114
+ input_text = gr.Textbox(
115
+ label="", placeholder="請輸入拼音或文字…",
116
+ lines=1, max_lines=1, elem_id="input-box"
117
+ )
 
118
 
119
+ # 自動預測開關及預測按鈕(預測按鈕初始隱藏)
120
+ with gr.Row():
121
+ auto_predict = gr.Checkbox(
122
+ value=True, label="自動預測(內容變更時觸發)", elem_id="auto-predict"
123
+ )
124
+ predict_button = gr.Button(
125
+ "預測", elem_id="predict-button", visible=False
126
+ )
127
 
128
  # 進階參數設定(可摺疊)
129
  with gr.Accordion("進階設定", open=False):
 
136
  m_slider = gr.Slider(
137
  minimum=1, maximum=30, step=1, value=6, label="M(建議數/Beam 數)"
138
  )
 
 
 
139
 
140
  # 事件綁定
141
+ auto_predict.change(
142
+ fn=lambda auto: update(visible=not auto),
143
+ inputs=[auto_predict],
144
+ outputs=[predict_button],
145
+ )
146
  predict_button.click(
147
  fn=suggest_next,
148
  inputs=[input_text, model_selector, k_slider, m_slider],