Spaces:
Sleeping
Sleeping
| from transformers import T5ForConditionalGeneration, T5Tokenizer | |
| import gradio as gr | |
| model = T5ForConditionalGeneration.from_pretrained("PRAli22/t5-base-text-summarizer") | |
| tokenizer = T5Tokenizer.from_pretrained("PRAli22/t5-base-text-summarizer") | |
| TEXT_LEN = 512 | |
| def summarize(text): | |
| inputs = tokenizer(text, | |
| max_length=TEXT_LEN, | |
| truncation=True, | |
| padding="max_length", | |
| add_special_tokens=True, | |
| return_tensors="pt") | |
| summarized_ids = model.generate( | |
| input_ids=inputs["input_ids"], | |
| attention_mask=inputs["attention_mask"], | |
| num_beams=4) | |
| 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() | |