import gradio as gr from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline import torch from langs import LANGS import os pipe1 = pipeline('text-generation', model='RamAnanth1/distilgpt2-sd-prompts') TASK = "translation" CKPT = "facebook/nllb-200-distilled-600M" model = AutoModelForSeq2SeqLM.from_pretrained(CKPT) tokenizer = AutoTokenizer.from_pretrained(CKPT) device = 0 if torch.cuda.is_available() else -1 import gradio as gr from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline import torch from langs import LANGS TASK = "translation" CKPT = "facebook/nllb-200-distilled-600M" model = AutoModelForSeq2SeqLM.from_pretrained(CKPT) tokenizer = AutoTokenizer.from_pretrained(CKPT) device = 0 if torch.cuda.is_available() else -1 def translate(text): """ Translate the text from source lang to target lang """ src_lang = "zho-Hans" tgt_lang = "eng_Latn" max_length = 400 translation_pipeline = pipeline(TASK, model=model, tokenizer=tokenizer, src_lang=src_lang, tgt_lang=tgt_lang, max_length=max_length, device=device) result = translation_pipeline(text) return result[0]['translation_text'] with gr.Blocks() as demo: gr.Markdown( """ #