blackhole33 commited on
Commit
372a9f8
·
verified ·
1 Parent(s): ba8cc6a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -1,18 +1,19 @@
1
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
2
  import gradio as gr
3
 
4
- model_ckpt = "booba-uz/english-uzbek-translation_v1"
5
  tokenizer = AutoTokenizer.from_pretrained(model_ckpt)
6
  model = AutoModelForSeq2SeqLM.from_pretrained(model_ckpt)
7
 
8
  tokenizer.src_lang = "en"
9
  tokenizer.tgt_lang = "uz"
 
10
 
11
 
12
  def translator(input_text,history):
13
- print(input_text)
14
  if not input_text.strip():
15
  return "Iltimos Gap kiriting"
 
16
  inputs = tokenizer(input_text, return_tensors="pt")
17
  outputs = model.generate(**inputs, max_length=256)
18
  translated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
@@ -27,9 +28,9 @@ demo = gr.ChatInterface(
27
  description="ENglish-UZbek Translator",
28
 
29
  theme="ocean",
30
- # examples=["The flight, which departed from Baku and was en route to Grozny, requested emergency landing clearance at the nearest airport prior to the crash. According to Kazakhstan's Emergency Situations Ministry, the crash site was engulfed in flames; however, reports confirm there are survivors among those onboard.",
31
- # "Footage of the crash, showing the dramatic scene at the airport, has circulated widely online. Authorities have launched an investigation to determine the cause of the incident and assess the condition of the survivors.",
32
- # "Preliminary findings suggest the crash may have been caused by a collision with a flock of birds.Further updates on the status of the passengers and crew are expected as emergency services continue their work at the site."],
33
  # cache_examples=True,
34
 
35
  )
 
1
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
2
  import gradio as gr
3
 
4
+ model_ckpt = "booba-uz/english-uzbek-translation_v2"
5
  tokenizer = AutoTokenizer.from_pretrained(model_ckpt)
6
  model = AutoModelForSeq2SeqLM.from_pretrained(model_ckpt)
7
 
8
  tokenizer.src_lang = "en"
9
  tokenizer.tgt_lang = "uz"
10
+ prefix = "Translate this text from English to uzbek: "
11
 
12
 
13
  def translator(input_text,history):
 
14
  if not input_text.strip():
15
  return "Iltimos Gap kiriting"
16
+ input_text = str(prefix + input_text)
17
  inputs = tokenizer(input_text, return_tensors="pt")
18
  outputs = model.generate(**inputs, max_length=256)
19
  translated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
 
28
  description="ENglish-UZbek Translator",
29
 
30
  theme="ocean",
31
+ examples=["The flight, which departed from Baku and was en route to Grozny, requested emergency landing clearance at the nearest airport prior to the crash. According to Kazakhstan's Emergency Situations Ministry, the crash site was engulfed in flames; however, reports confirm there are survivors among those onboard.",
32
+ "Footage of the crash, showing the dramatic scene at the airport, has circulated widely online. Authorities have launched an investigation to determine the cause of the incident and assess the condition of the survivors.",
33
+ "Preliminary findings suggest the crash may have been caused by a collision with a flock of birds.Further updates on the status of the passengers and crew are expected as emergency services continue their work at the site."]
34
  # cache_examples=True,
35
 
36
  )