Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -83,80 +83,56 @@ def translate_text(
|
|
83 |
description = """<p align="center">Enter Japanese text to translate it into Simplified Chinese.</p>"""
|
84 |
|
85 |
with gr.Blocks() as demo:
|
|
|
|
|
86 |
with gr.Row():
|
87 |
-
|
88 |
-
send_btn = gr.Button("Send", elem_id="send-btn")
|
89 |
-
clear_btn = gr.Button("Clear", elem_id="clear-btn")
|
90 |
-
retry_btn = gr.Button("Retry", elem_id="retry-btn")
|
91 |
-
undo_btn = gr.Button("Undo", elem_id="undo-btn")
|
92 |
|
93 |
with gr.Row():
|
94 |
-
with gr.Column():
|
95 |
-
|
96 |
-
lines=
|
97 |
placeholder="請輸入日文",
|
98 |
label="Input Japanese Text"
|
99 |
)
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
system_message = gr.Textbox(
|
107 |
-
value="你是一个轻小说翻译模型,可以流畅通顺地以日本轻小说的风格将日文翻译成简体中文,并联系上下文正确使用人称代词,不擅自添加原文中没有的代词。",
|
108 |
-
label="System message"
|
109 |
-
)
|
110 |
-
max_tokens_slider = gr.Slider(minimum=1, maximum=4096, value=512, step=1, label="Max tokens")
|
111 |
-
temperature_slider = gr.Slider(minimum=0.1, maximum=4.0, value=0.1, step=0.1, label="Temperature")
|
112 |
-
top_p_slider = gr.Slider(
|
113 |
-
minimum=0.1,
|
114 |
-
maximum=1.0,
|
115 |
-
value=0.3,
|
116 |
-
step=0.05,
|
117 |
-
label="Top-p",
|
118 |
)
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
)
|
133 |
-
output_text = gr.Textbox(
|
134 |
-
lines=2,
|
135 |
-
label="Translated Chinese Text"
|
136 |
-
)
|
137 |
-
|
138 |
-
send_btn.click(
|
139 |
-
translate_text,
|
140 |
-
inputs=[input_text, model_dropdown, system_message, max_tokens_slider, temperature_slider, top_p_slider, top_k_slider, repeat_penalty_slider],
|
141 |
-
outputs=output_text
|
142 |
-
)
|
143 |
-
|
144 |
-
clear_btn.click(
|
145 |
-
lambda: ("", ""),
|
146 |
-
inputs=[],
|
147 |
-
outputs=[input_text, output_text]
|
148 |
-
)
|
149 |
-
|
150 |
-
retry_btn.click(
|
151 |
-
lambda: None,
|
152 |
-
inputs=[],
|
153 |
-
outputs=[]
|
154 |
-
)
|
155 |
-
|
156 |
-
undo_btn.click(
|
157 |
-
lambda: None,
|
158 |
-
inputs=[],
|
159 |
-
outputs=[]
|
160 |
-
)
|
161 |
|
162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
description = """<p align="center">Enter Japanese text to translate it into Simplified Chinese.</p>"""
|
84 |
|
85 |
with gr.Blocks() as demo:
|
86 |
+
gr.Markdown("# Japanese to Chinese Translator")
|
87 |
+
|
88 |
with gr.Row():
|
89 |
+
gr.Button("Translate")
|
|
|
|
|
|
|
|
|
90 |
|
91 |
with gr.Row():
|
92 |
+
with gr.Column(scale=1):
|
93 |
+
input_textbox = gr.Textbox(
|
94 |
+
lines=5,
|
95 |
placeholder="請輸入日文",
|
96 |
label="Input Japanese Text"
|
97 |
)
|
98 |
+
|
99 |
+
with gr.Column(scale=1):
|
100 |
+
output_textbox = gr.Textbox(
|
101 |
+
lines=5,
|
102 |
+
label="Translated Chinese Text",
|
103 |
+
interactive=False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
)
|
105 |
+
|
106 |
+
def process_translation(input_text, model, system_message, max_tokens, temperature, top_p, top_k, repeat_penalty):
|
107 |
+
translated_text = translate_text(
|
108 |
+
input_text,
|
109 |
+
model,
|
110 |
+
system_message,
|
111 |
+
max_tokens,
|
112 |
+
temperature,
|
113 |
+
top_p,
|
114 |
+
top_k,
|
115 |
+
repeat_penalty
|
116 |
+
)
|
117 |
+
return translated_text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
|
119 |
+
gr.Interface(
|
120 |
+
fn=process_translation,
|
121 |
+
inputs=[
|
122 |
+
input_textbox,
|
123 |
+
gr.Dropdown([
|
124 |
+
'sakura-14b-qwen2beta-v0.9.2-q6k.gguf'
|
125 |
+
],
|
126 |
+
value="sakura-14b-qwen2beta-v0.9.2-q6k.gguf",
|
127 |
+
label="Model"
|
128 |
+
),
|
129 |
+
gr.Textbox(value="你是一个轻小说翻译模型,可以流畅通顺地以日本轻小说的风格将日文翻译成简体中文,并联系上下文正确使用人称代词,不擅自添加原文中没有的代词。", label="System message"),
|
130 |
+
gr.Slider(minimum=1, maximum=4096, value=512, step=1, label="Max tokens"),
|
131 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.1, step=0.1, label="Temperature"),
|
132 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.3, step=0.05, label="Top-p"),
|
133 |
+
gr.Slider(minimum=0, maximum=100, value=1, step=1, label="Top-k"),
|
134 |
+
gr.Slider(minimum=0.0, maximum=2.0, value=1.0, step=0.1, label="Repetition penalty"),
|
135 |
+
],
|
136 |
+
outputs=output_textbox,
|
137 |
+
live=True
|
138 |
+
).launch()
|