Spaces:
Running
on
Zero
Running
on
Zero
remove numbers from suggestions
Browse files
app.py
CHANGED
@@ -36,7 +36,7 @@ def get_pipeline(model_name):
|
|
36 |
@spaces.GPU
|
37 |
def suggest_next(text, model_name, k, m):
|
38 |
"""
|
39 |
-
使用 Beam Search 產生 m
|
40 |
"""
|
41 |
gen_pipe = get_pipeline(model_name)
|
42 |
outs = gen_pipe(
|
@@ -56,16 +56,15 @@ def suggest_next(text, model_name, k, m):
|
|
56 |
for s in suggestions:
|
57 |
if s not in unique_suggestions:
|
58 |
unique_suggestions.append(s)
|
59 |
-
#
|
60 |
-
|
61 |
-
return update(choices=numbered, value=None)
|
62 |
|
63 |
|
64 |
def append_suggestion(current, choice):
|
65 |
if choice is None:
|
66 |
return current
|
67 |
-
|
68 |
-
return current +
|
69 |
|
70 |
# 自訂 CSS:模擬經典中文輸入法候選欄樣式,並優化手機響應與自動高度
|
71 |
custom_css = """
|
@@ -189,4 +188,4 @@ with gr.Blocks(css=custom_css) as demo:
|
|
189 |
outputs=input_text,
|
190 |
)
|
191 |
|
192 |
-
demo.launch()
|
|
|
36 |
@spaces.GPU
|
37 |
def suggest_next(text, model_name, k, m):
|
38 |
"""
|
39 |
+
使用 Beam Search 產生 m 條候選,並一次更新候選列表,轉繁體並去除重複。
|
40 |
"""
|
41 |
gen_pipe = get_pipeline(model_name)
|
42 |
outs = gen_pipe(
|
|
|
56 |
for s in suggestions:
|
57 |
if s not in unique_suggestions:
|
58 |
unique_suggestions.append(s)
|
59 |
+
# 不編號,直接顯示文字
|
60 |
+
return update(choices=unique_suggestions, value=None)
|
|
|
61 |
|
62 |
|
63 |
def append_suggestion(current, choice):
|
64 |
if choice is None:
|
65 |
return current
|
66 |
+
# 直接插入選中的候選文字
|
67 |
+
return current + choice
|
68 |
|
69 |
# 自訂 CSS:模擬經典中文輸入法候選欄樣式,並優化手機響應與自動高度
|
70 |
custom_css = """
|
|
|
188 |
outputs=input_text,
|
189 |
)
|
190 |
|
191 |
+
demo.launch()
|