entropy25 commited on
Commit
99c70a3
·
verified ·
1 Parent(s): f2a0f58

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +216 -155
app.py CHANGED
@@ -3,11 +3,14 @@ import torch
3
  from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
4
  from peft import PeftModel
5
 
6
- # ==================== 模型加载 ====================
7
  base_model_name = "facebook/nllb-200-distilled-600M"
 
 
8
  adapter_en_to_no = "entropy25/mt_en_no_oil"
9
  adapter_no_to_en = "entropy25/mt_no_en_oil"
10
 
 
11
  tokenizer = AutoTokenizer.from_pretrained(base_model_name)
12
  base_model = AutoModelForSeq2SeqLM.from_pretrained(
13
  base_model_name,
@@ -16,10 +19,10 @@ base_model = AutoModelForSeq2SeqLM.from_pretrained(
16
  device_map="auto"
17
  )
18
 
 
19
  model_en_to_no = PeftModel.from_pretrained(base_model, adapter_en_to_no)
20
  model_no_to_en = PeftModel.from_pretrained(base_model, adapter_no_to_en)
21
 
22
- # ==================== 翻译函数 ====================
23
  def translate(text, source_lang, target_lang):
24
  if not text.strip():
25
  return ""
@@ -27,17 +30,19 @@ def translate(text, source_lang, target_lang):
27
  if source_lang == target_lang:
28
  return text
29
 
30
- # 选择模型
31
  if source_lang == "English" and target_lang == "Norwegian":
32
  model = model_en_to_no
 
33
  tgt_code = "nob_Latn"
34
  elif source_lang == "Norwegian" and target_lang == "English":
35
  model = model_no_to_en
 
36
  tgt_code = "eng_Latn"
37
  else:
38
  return "Unsupported language pair"
39
 
40
- # 翻译
41
  sentences = text.split('\n')
42
  translated_sentences = []
43
 
@@ -46,7 +51,12 @@ def translate(text, source_lang, target_lang):
46
  translated_sentences.append("")
47
  continue
48
 
49
- inputs = tokenizer(sentence, return_tensors="pt", truncation=True, max_length=512)
 
 
 
 
 
50
 
51
  if hasattr(model, 'device'):
52
  inputs = {k: v.to(model.device) for k, v in inputs.items()}
@@ -64,179 +74,255 @@ def translate(text, source_lang, target_lang):
64
  return '\n'.join(translated_sentences)
65
 
66
  def swap_languages(src, tgt, input_txt, output_txt):
67
- """交换语言方向"""
68
  return tgt, src, output_txt, input_txt
69
 
70
- # ==================== 示例数据 ====================
71
- EXAMPLES = {
72
- "English": {
73
- "drilling": "Mud weight adjusted to 1.82 specific gravity at 3,247 meters depth.",
74
- "reservoir": "Permeability is 250 millidarcy with 22 percent porosity.",
75
- "subsea": "Christmas tree rated for 10,000 psi working pressure.",
76
- "safety": "H2S training required before site access."
77
- },
78
- "Norwegian": {
79
- "drilling": "Slamvekt justert til 1,82 spesifikk tyngde ved 3 247 meters dybde.",
80
- "reservoir": "Permeabilitet er 250 millidarcy med 22 prosent porøsitet.",
81
- "subsea": "Juletre dimensjonert for 10 000 psi arbeidstrykk.",
82
- "safety": "H2S-opplæring påkrevd før tilgang til området."
83
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  }
85
 
86
- # ==================== CSS 样式 ====================
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  custom_css = """
88
  .gradio-container {
89
- max-width: 1200px !important;
90
- margin: 0 auto !important;
 
 
 
 
 
91
  }
92
  .translate-box {
93
- background: white;
94
- border: 1px solid #e5e7eb;
95
- border-radius: 8px;
96
- padding: 0;
97
- box-shadow: 0 1px 3px rgba(0,0,0,0.1);
 
 
 
 
 
98
  }
99
  .lang-selector {
100
- font-size: 16px !important;
101
- font-weight: 600 !important;
102
- padding: 12px !important;
103
- background: #f9fafb !important;
104
- border-radius: 8px 8px 0 0 !important;
105
  }
106
  .text-area textarea {
107
- font-size: 15px !important;
108
- line-height: 1.6 !important;
109
- padding: 16px !important;
110
- min-height: 180px !important;
111
  border: none !important;
112
- resize: vertical !important;
 
 
 
 
 
 
 
 
 
113
  }
114
  .swap-btn {
115
- width: 48px !important;
116
- height: 48px !important;
 
117
  border-radius: 50% !important;
118
- font-size: 20px !important;
119
  background: white !important;
120
- border: 2px solid #0ea5e9 !important;
121
- color: #0ea5e9 !important;
122
- transition: all 0.2s !important;
 
 
123
  }
124
  .swap-btn:hover {
125
- background: #0ea5e9 !important;
126
- color: white !important;
127
- transform: rotate(180deg) !important;
128
  }
129
- .example-btn {
130
- padding: 8px 16px !important;
131
- font-size: 14px !important;
132
- border-radius: 6px !important;
133
- background: #f1f5f9 !important;
134
- border: 1px solid #cbd5e1 !important;
135
- transition: all 0.2s !important;
136
- }
137
- .example-btn:hover {
138
- background: #e2e8f0 !important;
139
- border-color: #94a3b8 !important;
140
  }
141
  """
142
 
143
- # ==================== Gradio 界面 ====================
144
- with gr.Blocks(css=custom_css, theme=gr.themes.Soft(), title="Oil & Gas Translator") as demo:
145
 
146
- gr.Markdown(
147
- """
148
- # 🛢️ Oil & Gas Technical Translator
149
- ### English ↔ Norwegian Bidirectional Translation
150
- """
151
- )
152
 
153
- # 主翻译区域
154
  with gr.Row():
155
- with gr.Column(scale=5):
156
  with gr.Group(elem_classes="translate-box"):
157
- source_lang = gr.Dropdown(
158
- choices=["English", "Norwegian"],
159
- value="English",
160
- label="Source Language",
161
- elem_classes="lang-selector"
162
- )
 
 
 
 
163
  input_text = gr.Textbox(
164
- placeholder="Enter text to translate...",
165
  show_label=False,
166
- lines=6,
 
 
167
  elem_classes="text-area"
168
  )
169
 
170
- with gr.Column(scale=1, min_width=80):
171
- gr.HTML("<div style='height: 60px'></div>")
172
- swap_btn = gr.Button("⇄", elem_classes="swap-btn", size="sm")
173
 
174
- with gr.Column(scale=5):
175
  with gr.Group(elem_classes="translate-box"):
176
- target_lang = gr.Dropdown(
177
- choices=["English", "Norwegian"],
178
- value="Norwegian",
179
- label="Target Language",
180
- elem_classes="lang-selector"
181
- )
 
 
 
 
182
  output_text = gr.Textbox(
183
- placeholder="Translation will appear here...",
184
  show_label=False,
185
- lines=6,
 
 
186
  elem_classes="text-area",
187
  interactive=False
188
  )
189
 
190
- gr.Markdown("---")
 
 
 
 
191
 
192
- # 示例区域
193
- with gr.Row():
194
- with gr.Column():
195
- gr.Markdown("### 📝 Quick Examples")
196
- gr.Markdown("Click an example below to try it:")
197
-
198
- with gr.Row():
199
- drilling_btn = gr.Button("⛏️ Drilling", elem_classes="example-btn", scale=1)
200
- reservoir_btn = gr.Button("🗂️ Reservoir", elem_classes="example-btn", scale=1)
201
- subsea_btn = gr.Button("🌊 Subsea", elem_classes="example-btn", scale=1)
202
- safety_btn = gr.Button("⚠️ Safety", elem_classes="example-btn", scale=1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
203
 
204
- # 文件上传
205
- gr.Markdown("---")
206
- with gr.Accordion("📄 Upload Text File", open=False):
207
  file_input = gr.File(
208
  label="Upload a .txt file to translate",
209
- file_types=[".txt"]
 
210
  )
211
 
212
- # ==================== 事件绑定 ====================
213
-
214
- # 示例按钮点击
215
- def load_example(example_key, source_lang):
216
- return EXAMPLES[source_lang][example_key]
217
-
218
- drilling_btn.click(
219
- fn=lambda sl: load_example("drilling", sl),
220
- inputs=[source_lang],
221
- outputs=[input_text]
222
- )
223
- reservoir_btn.click(
224
- fn=lambda sl: load_example("reservoir", sl),
225
- inputs=[source_lang],
226
- outputs=[input_text]
227
- )
228
- subsea_btn.click(
229
- fn=lambda sl: load_example("subsea", sl),
230
- inputs=[source_lang],
231
- outputs=[input_text]
232
- )
233
- safety_btn.click(
234
- fn=lambda sl: load_example("safety", sl),
235
  inputs=[source_lang],
236
- outputs=[input_text]
237
  )
238
 
239
- # 翻译触发
240
  input_text.change(
241
  fn=translate,
242
  inputs=[input_text, source_lang, target_lang],
@@ -255,41 +341,16 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft(), title="Oil & Gas Translat
255
  outputs=output_text
256
  )
257
 
258
- # 交换语言
259
  swap_btn.click(
260
  fn=swap_languages,
261
  inputs=[source_lang, target_lang, input_text, output_text],
262
  outputs=[source_lang, target_lang, input_text, output_text]
263
  )
264
 
265
- # 文件上传
266
- def load_file(file):
267
- if file is None:
268
- return ""
269
- try:
270
- with open(file.name, 'r', encoding='utf-8') as f:
271
- return f.read()
272
- except:
273
- try:
274
- with open(file.name, 'r', encoding='latin-1') as f:
275
- return f.read()
276
- except Exception as e:
277
- return f"Error: {str(e)}"
278
-
279
  file_input.change(
280
  fn=load_file,
281
  inputs=file_input,
282
  outputs=input_text
283
  )
284
-
285
- # 页脚
286
- gr.Markdown(
287
- """
288
- ---
289
- <div style='text-align: center; color: #64748b; font-size: 13px;'>
290
- Powered by NLLB-200 + LoRA | Specialized for Oil & Gas Industry
291
- </div>
292
- """
293
- )
294
 
295
- demo.launch(share=False)
 
3
  from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
4
  from peft import PeftModel
5
 
6
+ # 基础模型
7
  base_model_name = "facebook/nllb-200-distilled-600M"
8
+
9
+ # 两个适配器模型
10
  adapter_en_to_no = "entropy25/mt_en_no_oil"
11
  adapter_no_to_en = "entropy25/mt_no_en_oil"
12
 
13
+ # 加载 tokenizer 和基础模型
14
  tokenizer = AutoTokenizer.from_pretrained(base_model_name)
15
  base_model = AutoModelForSeq2SeqLM.from_pretrained(
16
  base_model_name,
 
19
  device_map="auto"
20
  )
21
 
22
+ # 加载两个方向的模型
23
  model_en_to_no = PeftModel.from_pretrained(base_model, adapter_en_to_no)
24
  model_no_to_en = PeftModel.from_pretrained(base_model, adapter_no_to_en)
25
 
 
26
  def translate(text, source_lang, target_lang):
27
  if not text.strip():
28
  return ""
 
30
  if source_lang == target_lang:
31
  return text
32
 
33
+ # 选择正确的模型和语言代码
34
  if source_lang == "English" and target_lang == "Norwegian":
35
  model = model_en_to_no
36
+ src_code = "eng_Latn"
37
  tgt_code = "nob_Latn"
38
  elif source_lang == "Norwegian" and target_lang == "English":
39
  model = model_no_to_en
40
+ src_code = "nob_Latn"
41
  tgt_code = "eng_Latn"
42
  else:
43
  return "Unsupported language pair"
44
 
45
+ # 按行翻译
46
  sentences = text.split('\n')
47
  translated_sentences = []
48
 
 
51
  translated_sentences.append("")
52
  continue
53
 
54
+ inputs = tokenizer(
55
+ sentence,
56
+ return_tensors="pt",
57
+ truncation=True,
58
+ max_length=512
59
+ )
60
 
61
  if hasattr(model, 'device'):
62
  inputs = {k: v.to(model.device) for k, v in inputs.items()}
 
74
  return '\n'.join(translated_sentences)
75
 
76
  def swap_languages(src, tgt, input_txt, output_txt):
 
77
  return tgt, src, output_txt, input_txt
78
 
79
+ def load_file(file):
80
+ if file is None:
81
+ return ""
82
+
83
+ try:
84
+ with open(file.name, 'r', encoding='utf-8') as f:
85
+ return f.read()
86
+ except:
87
+ try:
88
+ with open(file.name, 'r', encoding='latin-1') as f:
89
+ return f.read()
90
+ except Exception as e:
91
+ return f"Error reading file: {str(e)}"
92
+
93
+ # 英语示例
94
+ EXAMPLES_EN = {
95
+ "drilling_short": "Mud weight adjusted to 1.82 specific gravity at 3,247 meters depth.",
96
+ "drilling_long": "The drilling operation at well site A-15 encountered unexpected high-pressure zones at 3,247 meters depth, requiring immediate adjustment of mud weight from 1.65 to 1.82 specific gravity to maintain wellbore stability and prevent potential kicks.",
97
+
98
+ "reservoir_short": "Permeability is 250 millidarcy with 22 percent porosity.",
99
+ "reservoir_long": "The reservoir shows excellent permeability of 250 millidarcy and porosity of 22 percent based on core analysis, indicating significant hydrocarbon potential with estimated oil saturation of 65 percent.",
100
+
101
+ "subsea_short": "Christmas tree rated for 10,000 psi working pressure.",
102
+ "subsea_long": "The subsea production system consists of a vertical Christmas tree rated for 10,000 psi working pressure and 150 degrees Celsius temperature, equipped with redundant safety features including automatic shutdown valves and real-time pressure monitoring systems.",
103
+
104
+ "seismic_short": "Structural trap area estimated at 12 square kilometers.",
105
+ "seismic_long": "Seismic data confirms the presence of a structural trap with an estimated area of 12 square kilometers, and productivity tests show stabilized oil production of 3,400 barrels per day at optimization pressure of 2,100 psi.",
106
+
107
+ "safety_short": "H2S training required before site access.",
108
+ "safety_long": "Emergency response procedures require all personnel to complete H2S safety training before site access, with breathing apparatus and wind indicators positioned at designated muster points, and immediate evacuation protocols activated when gas detection exceeds 10 ppm concentration levels."
109
  }
110
 
111
+ # 挪威语示例
112
+ EXAMPLES_NO = {
113
+ "drilling_short": "Slamvekt justert til 1,82 spesifikk tyngde ved 3 247 meters dybde.",
114
+ "drilling_long": "Boreoperasjonen ved brønnsted A-15 støtte på uventede høytrykksoner ved 3 247 meters dybde, noe som krevde umiddelbar justering av slamvekt fra 1,65 til 1,82 spesifikk tyngde for å opprettholde brønnborestabilitet og forhindre potensielle kicks.",
115
+
116
+ "reservoir_short": "Permeabilitet er 250 millidarcy med 22 prosent porøsitet.",
117
+ "reservoir_long": "Reservoaret viser utmerket permeabilitet på 250 millidarcy og porøsitet på 22 prosent basert på kjerneanalyse, noe som indikerer betydelig hydrokarbonpotensial med estimert oljemetning på 65 prosent.",
118
+
119
+ "subsea_short": "Juletre dimensjonert for 10 000 psi arbeidstrykk.",
120
+ "subsea_long": "Subsea produksjonssystemet består av et vertikalt juletre dimensjonert for 10 000 psi arbeidstrykk og 150 grader Celsius temperatur, utstyrt med redundante sikkerhetsfunksjoner inkludert automatiske nedstengningsventiler og sanntids trykkmonitorering.",
121
+
122
+ "seismic_short": "Strukturell felle estimert til 12 kvadratkilometer.",
123
+ "seismic_long": "Seismiske data bekrefter tilstedeværelsen av en strukturell felle med estimert areal på 12 kvadratkilometer, og produktivitetstester viser stabilisert oljeproduksjon på 3 400 fat per dag ved optimaliseringstrykk på 2 100 psi.",
124
+
125
+ "safety_short": "H2S-opplæring påkrevd før tilgang til området.",
126
+ "safety_long": "Nødprosedyrer krever at alt personell fullfører H2S-sikkerhetsopplæring før områdetilgang, med åndedrettsutstyr og vindindikatorer plassert ved utpekte samlingspunkter, og umiddelbare evakueringsprotokoller aktiveres når gassdeteksjon overskrider 10 ppm konsentrasjonsnivå."
127
+ }
128
+
129
+ def get_examples(source_lang):
130
+ """根据源语言返回对应的示例"""
131
+ if source_lang == "English":
132
+ return EXAMPLES_EN
133
+ else:
134
+ return EXAMPLES_NO
135
+
136
+ def update_example_buttons(source_lang):
137
+ """当语言改变时更新示例"""
138
+ examples = get_examples(source_lang)
139
+ return examples["drilling_short"]
140
+
141
  custom_css = """
142
  .gradio-container {
143
+ max-width: 1100px !important;
144
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif !important;
145
+ }
146
+ .main-container {
147
+ background: #f6f7f8 !important;
148
+ padding: 0 !important;
149
+ border-radius: 0 !important;
150
  }
151
  .translate-box {
152
+ background: white !important;
153
+ border-radius: 5px !important;
154
+ padding: 0 !important;
155
+ box-shadow: 0 2px 4px rgba(0,0,0,0.08) !important;
156
+ margin: 20px 0 !important;
157
+ }
158
+ .lang-header {
159
+ padding: 16px 20px !important;
160
+ border-bottom: 1px solid #e8eaed !important;
161
+ background: #fafafa !important;
162
  }
163
  .lang-selector {
164
+ border: none !important;
165
+ background: transparent !important;
166
+ font-size: 15px !important;
167
+ font-weight: 500 !important;
168
+ color: #333 !important;
169
  }
170
  .text-area textarea {
 
 
 
 
171
  border: none !important;
172
+ font-size: 17px !important;
173
+ line-height: 1.7 !important;
174
+ padding: 20px !important;
175
+ min-height: 200px !important;
176
+ }
177
+ .swap-container {
178
+ display: flex !important;
179
+ align-items: center !important;
180
+ justify-content: center !important;
181
+ padding: 20px 0 !important;
182
  }
183
  .swap-btn {
184
+ width: 44px !important;
185
+ height: 44px !important;
186
+ min-width: 44px !important;
187
  border-radius: 50% !important;
 
188
  background: white !important;
189
+ border: 1px solid #d1d5db !important;
190
+ box-shadow: 0 1px 3px rgba(0,0,0,0.1) !important;
191
+ font-size: 18px !important;
192
+ color: #0f6fff !important;
193
+ cursor: pointer !important;
194
  }
195
  .swap-btn:hover {
196
+ background: #f8f9fa !important;
197
+ border-color: #0f6fff !important;
 
198
  }
199
+ .footer-info {
200
+ text-align: center !important;
201
+ color: #999 !important;
202
+ font-size: 13px !important;
203
+ padding: 20px !important;
 
 
 
 
 
 
204
  }
205
  """
206
 
207
+ with gr.Blocks(css=custom_css, theme=gr.themes.Default()) as demo:
 
208
 
209
+ gr.HTML("<div style='height: 20px'></div>")
 
 
 
 
 
210
 
 
211
  with gr.Row():
212
+ with gr.Column(scale=1):
213
  with gr.Group(elem_classes="translate-box"):
214
+ with gr.Row(elem_classes="lang-header"):
215
+ source_lang = gr.Dropdown(
216
+ choices=["English", "Norwegian"],
217
+ value="English",
218
+ show_label=False,
219
+ container=False,
220
+ elem_classes="lang-selector",
221
+ scale=1
222
+ )
223
+
224
  input_text = gr.Textbox(
225
+ placeholder="Type to translate",
226
  show_label=False,
227
+ lines=8,
228
+ max_lines=20,
229
+ container=False,
230
  elem_classes="text-area"
231
  )
232
 
233
+ with gr.Column(scale=0, min_width=100):
234
+ with gr.Row(elem_classes="swap-container"):
235
+ swap_btn = gr.Button("⇄", elem_classes="swap-btn")
236
 
237
+ with gr.Column(scale=1):
238
  with gr.Group(elem_classes="translate-box"):
239
+ with gr.Row(elem_classes="lang-header"):
240
+ target_lang = gr.Dropdown(
241
+ choices=["English", "Norwegian"],
242
+ value="Norwegian",
243
+ show_label=False,
244
+ container=False,
245
+ elem_classes="lang-selector",
246
+ scale=1
247
+ )
248
+
249
  output_text = gr.Textbox(
250
+ placeholder="Translation",
251
  show_label=False,
252
+ lines=8,
253
+ max_lines=20,
254
+ container=False,
255
  elem_classes="text-area",
256
  interactive=False
257
  )
258
 
259
+ gr.HTML(
260
+ "<div class='footer-info'>"
261
+ "Oil & Gas Translation • English ↔ Norwegian • Bidirectional Model"
262
+ "</div>"
263
+ )
264
 
265
+ with gr.Accordion("Example Sentences", open=True):
266
+ with gr.Row():
267
+ example_text = gr.Textbox(
268
+ value=EXAMPLES_EN["drilling_short"],
269
+ label="",
270
+ lines=3,
271
+ max_lines=5,
272
+ show_copy_button=True
273
+ )
274
+ use_example_btn = gr.Button("Use This Example →", variant="primary", size="sm")
275
+
276
+ with gr.Row():
277
+ btn1 = gr.Button("Drilling (Short)", size="sm")
278
+ btn2 = gr.Button("Drilling (Long)", size="sm")
279
+ btn3 = gr.Button("Reservoir (Short)", size="sm")
280
+ btn4 = gr.Button("Reservoir (Long)", size="sm")
281
+ btn5 = gr.Button("Subsea (Short)", size="sm")
282
+
283
+ with gr.Row():
284
+ btn6 = gr.Button("Subsea (Long)", size="sm")
285
+ btn7 = gr.Button("Seismic (Short)", size="sm")
286
+ btn8 = gr.Button("Seismic (Long)", size="sm")
287
+ btn9 = gr.Button("Safety (Short)", size="sm")
288
+ btn10 = gr.Button("Safety (Long)", size="sm")
289
+
290
+ # 为每个按钮设置点击事件,根据当前源语言选择示例
291
+ def get_example(key, source_lang):
292
+ examples = get_examples(source_lang)
293
+ return examples[key]
294
+
295
+ btn1.click(lambda sl: get_example("drilling_short", sl), inputs=[source_lang], outputs=example_text)
296
+ btn2.click(lambda sl: get_example("drilling_long", sl), inputs=[source_lang], outputs=example_text)
297
+ btn3.click(lambda sl: get_example("reservoir_short", sl), inputs=[source_lang], outputs=example_text)
298
+ btn4.click(lambda sl: get_example("reservoir_long", sl), inputs=[source_lang], outputs=example_text)
299
+ btn5.click(lambda sl: get_example("subsea_short", sl), inputs=[source_lang], outputs=example_text)
300
+ btn6.click(lambda sl: get_example("subsea_long", sl), inputs=[source_lang], outputs=example_text)
301
+ btn7.click(lambda sl: get_example("seismic_short", sl), inputs=[source_lang], outputs=example_text)
302
+ btn8.click(lambda sl: get_example("seismic_long", sl), inputs=[source_lang], outputs=example_text)
303
+ btn9.click(lambda sl: get_example("safety_short", sl), inputs=[source_lang], outputs=example_text)
304
+ btn10.click(lambda sl: get_example("safety_long", sl), inputs=[source_lang], outputs=example_text)
305
+
306
+ use_example_btn.click(
307
+ fn=lambda x: x,
308
+ inputs=example_text,
309
+ outputs=input_text
310
+ )
311
 
312
+ with gr.Accordion("Upload Text File", open=False):
 
 
313
  file_input = gr.File(
314
  label="Upload a .txt file to translate",
315
+ file_types=[".txt"],
316
+ type="filepath"
317
  )
318
 
319
+ # 当源语言改变时,更新示例显示
320
+ source_lang.change(
321
+ fn=update_example_buttons,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
322
  inputs=[source_lang],
323
+ outputs=[example_text]
324
  )
325
 
 
326
  input_text.change(
327
  fn=translate,
328
  inputs=[input_text, source_lang, target_lang],
 
341
  outputs=output_text
342
  )
343
 
 
344
  swap_btn.click(
345
  fn=swap_languages,
346
  inputs=[source_lang, target_lang, input_text, output_text],
347
  outputs=[source_lang, target_lang, input_text, output_text]
348
  )
349
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
350
  file_input.change(
351
  fn=load_file,
352
  inputs=file_input,
353
  outputs=input_text
354
  )
 
 
 
 
 
 
 
 
 
 
355
 
356
+ demo.launch()