sadzxctv commited on
Commit
6da03bd
1 Parent(s): 5f3b14e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -66
app.py CHANGED
@@ -82,76 +82,52 @@ def translate_text(
82
 
83
  description = """<p align="center">Enter Japanese text to translate it into Simplified Chinese.</p>"""
84
 
85
- def copy_to_clipboard(text):
86
- import pyperclip
87
- pyperclip.copy(text)
88
- return "Text copied to clipboard!"
89
-
90
- demo = gr.Blocks()
91
-
92
- with demo:
93
- gr.Markdown(description)
94
-
95
- with gr.Row():
96
- with gr.Column():
97
- input_textbox = gr.Textbox(
98
- lines=10,
99
- placeholder="請輸入日文",
100
- label="Input Japanese Text"
101
- )
102
- translate_button = gr.Button("翻譯")
103
-
104
- with gr.Column():
105
- output_textbox = gr.Textbox(
106
- lines=10,
107
- label="Translated Chinese Text",
108
- interactive=False
109
- )
110
- copy_button = gr.Button("複製結果")
111
-
112
- translate_button.click(
113
- fn=translate_text,
114
- inputs=[
115
- input_textbox,
116
- gr.Dropdown([
117
  'sakura-14b-qwen2beta-v0.9.2-q6k.gguf'
118
  ],
119
  value="sakura-14b-qwen2beta-v0.9.2-q6k.gguf",
120
  label="Model"
121
- ),
122
- gr.Textbox(value="你是一个轻小说翻译模型,可以流畅通顺地以日本轻小说的风格将日文翻译成简体中文,并联系上下文正确使用人称代词,不擅自添加原文中没有的代词。", label="System message"),
123
- gr.Slider(minimum=1, maximum=4096, value=512, step=1, label="Max tokens"),
124
- gr.Slider(minimum=0.1, maximum=4.0, value=0.1, step=0.1, label="Temperature"),
125
- gr.Slider(
126
- minimum=0.1,
127
- maximum=1.0,
128
- value=0.3,
129
- step=0.05,
130
- label="Top-p",
131
- ),
132
- gr.Slider(
133
- minimum=0,
134
- maximum=100,
135
- value=1,
136
- step=1,
137
- label="Top-k",
138
- ),
139
- gr.Slider(
140
- minimum=0.0,
141
- maximum=2.0,
142
- value=1.0,
143
- step=0.1,
144
- label="Repetition penalty",
145
- ),
146
- ],
147
- outputs=output_textbox
148
- )
149
-
150
- copy_button.click(
151
- fn=copy_to_clipboard,
152
- inputs=output_textbox,
153
- outputs=None # No need to update output
154
- )
155
 
156
  if __name__ == "__main__":
157
  demo.launch()
 
82
 
83
  description = """<p align="center">Enter Japanese text to translate it into Simplified Chinese.</p>"""
84
 
85
+ demo = gr.Interface(
86
+ fn=translate_text,
87
+ inputs=[
88
+ gr.Textbox(
89
+ lines=2,
90
+ placeholder="請輸入日文",
91
+ label="Input Japanese Text"
92
+ ),
93
+ gr.Dropdown([
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  'sakura-14b-qwen2beta-v0.9.2-q6k.gguf'
95
  ],
96
  value="sakura-14b-qwen2beta-v0.9.2-q6k.gguf",
97
  label="Model"
98
+ ),
99
+ gr.Textbox(value="你是一个轻小说翻译模型,可以流畅通顺地以日本轻小说的风格将日文翻译成简体中文,并联系上下文正确使用人称代词,不擅自添加原文中没有的代词。", label="System message"),
100
+ gr.Slider(minimum=1, maximum=4096, value=512, step=1, label="Max tokens"),
101
+ gr.Slider(minimum=0.1, maximum=4.0, value=0.1, step=0.1, label="Temperature"),
102
+ gr.Slider(
103
+ minimum=0.1,
104
+ maximum=1.0,
105
+ value=0.3,
106
+ step=0.05,
107
+ label="Top-p",
108
+ ),
109
+ gr.Slider(
110
+ minimum=0,
111
+ maximum=100,
112
+ value=1,
113
+ step=1,
114
+ label="Top-k",
115
+ ),
116
+ gr.Slider(
117
+ minimum=0.0,
118
+ maximum=2.0,
119
+ value=1.0,
120
+ step=0.1,
121
+ label="Repetition penalty",
122
+ ),
123
+ ],
124
+ outputs=gr.Textbox(
125
+ lines=2,
126
+ label="Translated Chinese Text"
127
+ ),
128
+ title="Japanese to Chinese Translator",
129
+ description=description
130
+ )
 
131
 
132
  if __name__ == "__main__":
133
  demo.launch()