Spaces:
Running
on
Zero
Running
on
Zero
smartphone friednly layout
Browse files
app.py
CHANGED
@@ -60,7 +60,7 @@ def append_suggestion(current, choice):
|
|
60 |
text = choice.split(". ", 1)[1] if ". " in choice else choice
|
61 |
return current + text
|
62 |
|
63 |
-
# 自訂 CSS
|
64 |
custom_css = """
|
65 |
#suggestions-bar {
|
66 |
width: 100%;
|
@@ -72,18 +72,14 @@ custom_css = """
|
|
72 |
background: #fff;
|
73 |
border: 1px solid #999;
|
74 |
border-radius: 4px;
|
75 |
-
padding:
|
76 |
overflow-x: auto;
|
77 |
white-space: nowrap;
|
78 |
}
|
79 |
-
#suggestions-bar .candidate-list input[type=radio] {
|
80 |
-
display: none;
|
81 |
-
}
|
82 |
#suggestions-bar .candidate-list label {
|
83 |
-
position: relative;
|
84 |
cursor: pointer;
|
85 |
-
padding:
|
86 |
-
font-size:
|
87 |
}
|
88 |
#suggestions-bar .candidate-list label:hover {
|
89 |
background: #f5f5f5;
|
@@ -92,20 +88,53 @@ custom_css = """
|
|
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",
|
@@ -113,10 +142,9 @@ with gr.Blocks(css=custom_css) as demo:
|
|
113 |
)
|
114 |
input_text = gr.Textbox(
|
115 |
label="", placeholder="請輸入拼音或文字…",
|
116 |
-
lines=1, max_lines=
|
117 |
)
|
118 |
|
119 |
-
# 自動預測開關及預測按鈕(預測按鈕初始隱藏)
|
120 |
with gr.Row():
|
121 |
auto_predict = gr.Checkbox(
|
122 |
value=True, label="自動預測(內容變更時觸發)", elem_id="auto-predict"
|
@@ -125,7 +153,6 @@ with gr.Blocks(css=custom_css) as demo:
|
|
125 |
"預測", elem_id="predict-button", visible=False
|
126 |
)
|
127 |
|
128 |
-
# 進階參數設定(可摺疊)
|
129 |
with gr.Accordion("進階設定", open=False):
|
130 |
model_selector = gr.Dropdown(
|
131 |
MODEL_LIST, value=MODEL_LIST[0], label="模型"
|
@@ -137,7 +164,6 @@ with gr.Blocks(css=custom_css) as demo:
|
|
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],
|
|
|
60 |
text = choice.split(". ", 1)[1] if ". " in choice else choice
|
61 |
return current + text
|
62 |
|
63 |
+
# 自訂 CSS:模擬經典中文輸入法候選欄樣式,並優化手機響應與自動高度
|
64 |
custom_css = """
|
65 |
#suggestions-bar {
|
66 |
width: 100%;
|
|
|
72 |
background: #fff;
|
73 |
border: 1px solid #999;
|
74 |
border-radius: 4px;
|
75 |
+
padding: 6px;
|
76 |
overflow-x: auto;
|
77 |
white-space: nowrap;
|
78 |
}
|
|
|
|
|
|
|
79 |
#suggestions-bar .candidate-list label {
|
|
|
80 |
cursor: pointer;
|
81 |
+
padding: 6px 10px;
|
82 |
+
font-size: 16px;
|
83 |
}
|
84 |
#suggestions-bar .candidate-list label:hover {
|
85 |
background: #f5f5f5;
|
|
|
88 |
background: #e6f7ff;
|
89 |
border: 1px solid #1890ff;
|
90 |
}
|
91 |
+
#input-box textarea {
|
92 |
+
width: 100%;
|
93 |
+
font-size: 16px;
|
94 |
+
padding: 6px;
|
95 |
+
box-sizing: border-box;
|
96 |
+
overflow: hidden;
|
97 |
+
resize: none;
|
98 |
+
}
|
99 |
+
#predict-button {
|
100 |
+
margin-top: 8px;
|
101 |
width: 100%;
|
102 |
}
|
103 |
+
/* 手機響應式 */
|
104 |
+
@media only screen and (max-width: 600px) {
|
105 |
+
#suggestions-bar .candidate-list label {
|
106 |
+
padding: 8px;
|
107 |
+
font-size: 18px;
|
108 |
+
}
|
109 |
+
#predict-button {
|
110 |
+
font-size: 18px;
|
111 |
+
}
|
112 |
+
}
|
113 |
+
"""
|
114 |
+
|
115 |
+
# 自動增高腳本
|
116 |
+
auto_height_js = """
|
117 |
+
<script>
|
118 |
+
window.addEventListener('load', () => {
|
119 |
+
const textarea = document.querySelector('#input-box textarea');
|
120 |
+
if (!textarea) return;
|
121 |
+
textarea.style.height = 'auto';
|
122 |
+
textarea.addEventListener('input', function() {
|
123 |
+
this.style.height = 'auto';
|
124 |
+
this.style.height = this.scrollHeight + 'px';
|
125 |
+
});
|
126 |
+
});
|
127 |
+
</script>
|
128 |
"""
|
129 |
|
130 |
with gr.Blocks(css=custom_css) as demo:
|
131 |
+
gr.HTML(auto_height_js)
|
132 |
gr.Markdown(
|
133 |
"## 🇹🇼 繁體中文 IME 加速器 \
|
134 |
"
|
135 |
"結合小型語言模型與 ZeroGPU,提供即時輸入法風格候選欄。"
|
136 |
)
|
137 |
|
|
|
138 |
with gr.Column():
|
139 |
suggestions = gr.Radio(
|
140 |
[], label="", interactive=True, type="value",
|
|
|
142 |
)
|
143 |
input_text = gr.Textbox(
|
144 |
label="", placeholder="請輸入拼音或文字…",
|
145 |
+
lines=1, max_lines=20, elem_id="input-box"
|
146 |
)
|
147 |
|
|
|
148 |
with gr.Row():
|
149 |
auto_predict = gr.Checkbox(
|
150 |
value=True, label="自動預測(內容變更時觸發)", elem_id="auto-predict"
|
|
|
153 |
"預測", elem_id="predict-button", visible=False
|
154 |
)
|
155 |
|
|
|
156 |
with gr.Accordion("進階設定", open=False):
|
157 |
model_selector = gr.Dropdown(
|
158 |
MODEL_LIST, value=MODEL_LIST[0], label="模型"
|
|
|
164 |
minimum=1, maximum=30, step=1, value=6, label="M(建議數/Beam 數)"
|
165 |
)
|
166 |
|
|
|
167 |
auto_predict.change(
|
168 |
fn=lambda auto: update(visible=not auto),
|
169 |
inputs=[auto_predict],
|