Spaces:
Sleeping
Sleeping
File size: 1,861 Bytes
337fc64 3249698 f37e9d0 372a9f8 337fc64 f37e9d0 337fc64 372a9f8 f37e9d0 5ca8da0 f37e9d0 bf8f11e 337fc64 f37e9d0 455138a f37e9d0 337fc64 f37e9d0 165daa8 ba8cc6a f37e9d0 372a9f8 455138a f37e9d0 337fc64 d0b7d87 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
import gradio as gr
model_ckpt = "booba-uz/english-uzbek-translation_v2"
tokenizer = AutoTokenizer.from_pretrained(model_ckpt)
model = AutoModelForSeq2SeqLM.from_pretrained(model_ckpt)
tokenizer.src_lang = "en"
tokenizer.tgt_lang = "uz"
prefix = "Translate this text from English to uzbek: "
def translator(input_text,history):
if not input_text.strip():
return "Iltimos Gap kiriting"
input_text = str(prefix + input_text)
inputs = tokenizer(input_text, return_tensors="pt")
outputs = model.generate(**inputs, max_length=256)
translated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
return translated_text[3:]
demo = gr.ChatInterface(
fn=translator,
type="messages",
chatbot=gr.Chatbot(height=300),
textbox=gr.Textbox(placeholder="Enter text..", container=False, scale=7),
title="Booba Translator",
description="ENglish-UZbek Translator",
theme="ocean",
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.",
"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.",
"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."]
# cache_examples=True,
)
demo.launch(debug=True)
|