YuLu0713 commited on
Commit
f8500fe
·
verified ·
1 Parent(s): 2ae1e56

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +186 -0
app.py ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+
4
+ # 支持的语言选项
5
+ LANGUAGES = {
6
+ "Auto Detect": "auto",
7
+ "English": "English",
8
+ "Chinese": "Chinese",
9
+ "Traditional Chinese": "Traditional Chinese",
10
+ "Russian": "Russian",
11
+ "Japanese": "Japanese",
12
+ "Korean": "Korean",
13
+ "Spanish": "Spanish",
14
+ "French": "French",
15
+ "Portuguese": "Portuguese",
16
+ "German": "German",
17
+ "Italian": "Italian",
18
+ "Thai": "Thai",
19
+ "Vietnamese": "Vietnamese",
20
+ "Indonesian": "Indonesian",
21
+ "Malay": "Malay",
22
+ "Arabic": "Arabic",
23
+ "Hindi": "Hindi",
24
+ "Hebrew": "Hebrew",
25
+ "Burmese": "Burmese",
26
+ "Tamil": "Tamil",
27
+ "Urdu": "Urdu",
28
+ "Bengali": "Bengali",
29
+ "Polish": "Polish",
30
+ "Dutch": "Dutch",
31
+ "Romanian": "Romanian",
32
+ "Turkish": "Turkish",
33
+ "Khmer": "Khmer",
34
+ "Lao": "Lao",
35
+ "Cantonese": "Cantonese",
36
+ "Czech": "Czech",
37
+ "Greek": "Greek",
38
+ "Swedish": "Swedish",
39
+ "Hungarian": "Hungarian",
40
+ "Danish": "Danish",
41
+ "Finnish": "Finnish",
42
+ "Ukrainian": "Ukrainian",
43
+ "Bulgarian": "Bulgarian",
44
+ "Serbian": "Serbian",
45
+ "Telugu": "Telugu",
46
+ "Afrikaans": "Afrikaans",
47
+ "Armenian": "Armenian",
48
+ "Assamese": "Assamese",
49
+ "Asturian": "Asturian",
50
+ "Basque": "Basque",
51
+ "Belarusian": "Belarusian",
52
+ "Bosnian": "Bosnian",
53
+ "Catalan": "Catalan",
54
+ "Cebuano": "Cebuano",
55
+ "Croatian": "Croatian",
56
+ "Egyptian Arabic": "Egyptian Arabic",
57
+ "Estonian": "Estonian",
58
+ "Galician": "Galician",
59
+ "Georgian": "Georgian",
60
+ "Gujarati": "Gujarati",
61
+ "Icelandic": "Icelandic",
62
+ "Javanese": "Javanese",
63
+ "Kannada": "Kannada",
64
+ "Kazakh": "Kazakh",
65
+ "Latvian": "Latvian",
66
+ "Lithuanian": "Lithuanian",
67
+ "Luxembourgish": "Luxembourgish",
68
+ "Macedonian": "Macedonian",
69
+ "Maithili": "Maithili",
70
+ "Maltese": "Maltese",
71
+ "Marathi": "Marathi",
72
+ "Mesopotamian Arabic": "Mesopotamian Arabic",
73
+ "Moroccan Arabic": "Moroccan Arabic",
74
+ "Najdi Arabic": "Najdi Arabic",
75
+ "Nepali": "Nepali",
76
+ "North Azerbaijani": "North Azerbaijani",
77
+ "North Levantine Arabic": "North Levantine Arabic",
78
+ "Northern Uzbek": "Northern Uzbek",
79
+ "Norwegian Bokmål": "Norwegian Bokmål",
80
+ "Norwegian Nynorsk": "Norwegian Nynorsk",
81
+ "Occitan": "Occitan",
82
+ "Odia": "Odia",
83
+ "Pangasinan": "Pangasinan",
84
+ "Sicilian": "Sicilian",
85
+ "Sindhi": "Sindhi",
86
+ "Sinhala": "Sinhala",
87
+ "Slovak": "Slovak",
88
+ "Slovenian": "Slovenian",
89
+ "South Levantine Arabic": "South Levantine Arabic",
90
+ "Swahili": "Swahili",
91
+ "Tagalog": "Tagalog",
92
+ "Ta’izzi-Adeni Arabic": "Ta’izzi-Adeni Arabic",
93
+ "Tosk Albanian": "Tosk Albanian",
94
+ "Tunisian Arabic": "Tunisian Arabic",
95
+ "Venetian": "Venetian",
96
+ "Waray": "Waray",
97
+ "Welsh": "Welsh",
98
+ "Western Persian": "Western Persian"
99
+ }
100
+
101
+
102
+ def translate_text(text, source_lang, target_lang):
103
+ if not text.strip():
104
+ return "请输入要翻译的文本"
105
+
106
+ try:
107
+ response = 'Test Seed-X'
108
+ yield response
109
+ except Exception as e:
110
+ yield f"翻译出错: {str(e)}"
111
+
112
+
113
+ # 创建 Gradio 界面
114
+ with gr.Blocks(title="Qwen3-MT Translator") as demo:
115
+ gr.Markdown("# 🌍 Seed-X")
116
+ # gr.Markdown(
117
+ # 'A real-time translation tool based on the Qwen3-MT model<br><a href="https://www.alibabacloud.com/help/en/model-studio/translation-abilities" target="_blank">Learn more about Qwen3-MT and API documentation</a>',
118
+ # elem_id="desc"
119
+ # )
120
+ gr.Image(
121
+ value="https://github.com/ByteDance-Seed/Seed-X-7B/blob/main/imgs/LOGO.jpg",
122
+ label="Seed-X",
123
+ show_label=False,
124
+ show_download_button=False,
125
+ interactive=False,
126
+ height=60
127
+ )
128
+
129
+ with gr.Row():
130
+ with gr.Column():
131
+ source_text = gr.Textbox(
132
+ label="Input Text",
133
+ placeholder="Please enter the text to translate...",
134
+ lines=5
135
+ )
136
+ with gr.Row():
137
+ source_lang = gr.Dropdown(
138
+ choices=list(LANGUAGES.keys()),
139
+ value="Auto Detect",
140
+ label="Source Language"
141
+ )
142
+ target_lang = gr.Dropdown(
143
+ choices=list(LANGUAGES.keys())[1:], # Exclude "Auto Detect"
144
+ value="English",
145
+ label="Target Language"
146
+ )
147
+ translate_btn = gr.Button("Translate", variant="primary")
148
+
149
+ with gr.Column():
150
+ target_text = gr.Textbox(
151
+ label="Translation Result",
152
+ interactive=False,
153
+ lines=5
154
+ )
155
+
156
+ # # 示例
157
+ # gr.Examples(
158
+ # examples=[
159
+ # ["你好,世界!", "Chinese", "English"],
160
+ # ["Hello, how are you today?", "English", "Chinese"],
161
+ # ["私は学生です。", "Japanese", "Chinese"],
162
+ # ["Bonjour, comment allez-vous?", "French", "English"]
163
+ # ],
164
+ # inputs=[source_text, source_lang, target_lang],
165
+ # outputs=target_text,
166
+ # fn=translate_text,
167
+ # cache_examples=True
168
+ # )
169
+
170
+ # 按钮点击事件
171
+ translate_btn.click(
172
+ fn=translate_text,
173
+ inputs=[source_text, source_lang, target_lang],
174
+ outputs=target_text
175
+ )
176
+
177
+ # 支持回车键翻译
178
+ source_text.submit(
179
+ fn=translate_text,
180
+ inputs=[source_text, source_lang, target_lang],
181
+ outputs=target_text
182
+ )
183
+
184
+ # 启动应用
185
+ if __name__ == "__main__":
186
+ demo.launch()