File size: 1,358 Bytes
a7eb2da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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()