|
import gradio as gr |
|
import transformers |
|
from transformers import MBartForConditionalGeneration, AutoModelForSeq2SeqLM |
|
from transformers import AlbertTokenizer, AutoTokenizer |
|
|
|
tokenizer = AlbertTokenizer.from_pretrained("ai4bharat/MultiIndicWikiBioSS", do_lower_case=False, use_fast=False, keep_accents=True) |
|
|
|
|
|
|
|
|
|
qgmodel = AutoModelForSeq2SeqLM.from_pretrained("ai4bharat/MultiIndicQuestionGenerationSS").eval() |
|
hgmodel = AutoModelForSeq2SeqLM.from_pretrained("ai4bharat/MultiIndicHeadlineGenerationSS").eval() |
|
ssmodel = AutoModelForSeq2SeqLM.from_pretrained("ai4bharat/MultiIndicSentenceSummarizationSS").eval() |
|
ppmodel = AutoModelForSeq2SeqLM.from_pretrained("ai4bharat/MultiIndicParaphraseGenerationSS").eval() |
|
wbmodel = AutoModelForSeq2SeqLM.from_pretrained("ai4bharat/MultiIndicWikiBioSS").eval() |
|
|
|
|
|
bos_id = tokenizer._convert_token_to_id_with_added_voc("<s>") |
|
eos_id = tokenizer._convert_token_to_id_with_added_voc("</s>") |
|
pad_id = tokenizer._convert_token_to_id_with_added_voc("<pad>") |
|
|
|
|
|
|
|
|
|
def greet(choice, lang, input): |
|
if choice == "IndicWikiBio": |
|
model = wbmodel |
|
elif choice == "IndicHeadlineGeneration": |
|
model = hgmodel |
|
elif choice == "IndicParaprasing": |
|
model = ppmodel |
|
elif choice == "IndicSentenceSummarization": |
|
model = ssmodel |
|
elif choice == "IndicQuestionGeneration": |
|
model = qgmodel |
|
|
|
|
|
inp = tokenizer(input.strip() + " </s> <2" + lang + ">", add_special_tokens=False, return_tensors="pt", padding=True).input_ids |
|
model_output=model.generate(inp, use_cache=True, num_beams=1, max_length=100, min_length=1, early_stopping=True, pad_token_id=pad_id, bos_token_id=bos_id, eos_token_id=eos_id, decoder_start_token_id=tokenizer._convert_token_to_id_with_added_voc("<2"+lang+">")) |
|
|
|
|
|
|
|
|
|
decoded_output=tokenizer.decode(model_output[0], skip_special_tokens=True, clean_up_tokenization_spaces=False) |
|
|
|
return decoded_output |
|
|
|
iface = gr.Interface(fn=greet, inputs=[gr.inputs.Dropdown("IndicWikiBio", "IndicHeadlineGeneration", "IndicParaprasing", "IndicSentenceSummarization", "IndicQuestionGeneration"), gr.inputs.Dropdown("as","bn", "gu", "hi", "kn", "ml", "mr", "or", "pa", "ta", "te"), "text"], outputs="text") |
|
iface.launch() |