File size: 1,088 Bytes
39402b7
 
 
 
 
 
 
 
feb80ee
475ee6f
 
feb80ee
39402b7
 
 
 
 
 
 
 
 
 
 
6e8ee24
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import gradio as gr
import transformers
from transformers import BartTokenizer, BartForConditionalGeneration

model_name = 'facebook/bart-large-cnn'
tokenizer = BartTokenizer.from_pretrained(model_name)
model = BartForConditionalGeneration.from_pretrained(model_name)

def summarize(input_text):
    if not input_text:
        return ''
    inp = tokenizer.encode("summarize: " + input_text.replace('\n',''), return_tensors="pt", max_length=1024, truncation=True)
    summary_ids = model.generate(inp, num_beams=4, max_length=150, early_stopping=True)
    summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
    return summary

app = gr.Interface(
    fn=summarize, 
    inputs=gr.Textbox(lines=7, label="Input Text"), 
    outputs="text",  
    css="footer {visibility: hidden}",
    article = """<p style='text-align: center;'>Hello, thanks for coming, visit AI tools: <a href="https://www.genelify.com" target="_blank">Genelify</a>, visit Social Media tools: <a href="https://www.tubtic.com" target="_blank">Tubtic</a></p>"""
)
app.launch(show_api=False, inline=False)