File size: 1,024 Bytes
a885c80
 
 
 
 
0621dcf
a885c80
 
ecff4a2
a885c80
ecff4a2
 
a885c80
 
 
 
809d949
a885c80
 
 
 
 
55d9e6b
 
a885c80
 
 
0621dcf
a885c80
 
 
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
# import gradio as gr

# gr.Interface.load("models/Abijith/Text-summarizer-t5-small").launch()

import os
import gradio as gr
from transformers import AutoTokenizer, T5ForConditionalGeneration

model_name = 'Abijith/Billsum-text-summarizer-t5-small'
# Load model directly
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = T5ForConditionalGeneration.from_pretrained(model_name)

def summarize_text(input_text):
    summar_input = 'summarize: '+input_text
    input_tokens = tokenizer(summar_input, return_tensors='pt').input_ids
    outputs = model.generate(input_tokens, max_new_tokens=100, min_new_tokens=30, do_sample=False)
    return tokenizer.decode(outputs[0], skip_special_tokens=True)

# Interface for the Gradio app
iface = gr.Interface(
    fn=summarize_text,
    inputs=gr.Textbox(lines=5, label="Input Text"),
    outputs=gr.Textbox(label="Summary"),
    title="Text Summarizer",
    description="Enter a paragraph, and the app will provide a summary.",
)

# Launch the Gradio app
iface.launch()