t5_sentiment / app.py
PRAli22's picture
Create app.py
395eb19
raw
history blame
1.25 kB
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 " ".join([tokenizer.decode(token_ids, skip_special_tokens=True)
for token_ids in summarized_ids])
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="summary"),
title="Text Summarizer",
description= "This is Text Summarizer System, it takes a text in English as inputs and returns it's summary",
css = css_code
)
demo.launch()