from transformers import AutoTokenizer, AutoModelForSeq2SeqLM import gradio as gr model = AutoModelForSeq2SeqLM.from_pretrained("PRAli22/flan-t5-base-imdb-text-classification") tokenizer = AutoTokenizer.from_pretrained("PRAli22/flan-t5-base-imdb-text-classification") def summarize(text): inputs = tokenizer.encode_plus(text, padding='max_length', max_length=512, return_tensors='pt') summarized_ids = model.generate(inputs['input_ids'], attention_mask=inputs['attention_mask'], max_length=150, num_beams=4, early_stopping=True) return tokenizer.decode(summarized_ids[0], skip_special_tokens=True) css_code='body{background-image:url("https://media.istockphoto.com/id/1256252051/vector/people-using-online-translation-app.jpg?s=612x612&w=0&k=20&c=aa6ykHXnSwqKu31fFR6r6Y1bYMS5FMAU9yHqwwylA94=");}' demo = gr.Interface( fn=summarize, inputs= gr.Textbox(label="text", placeholder="Enter the text "), outputs=gr.Textbox(label="sentiment"), title="Sentiment Classifier", description= "This is Sentiment Classifier, it takes a text in English as inputs and returns the sentiment", css = css_code ) demo.launch()