text-summarizer / app.py
genelify's picture
Update app.py
feb80ee verified
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):
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(inline=False, show_api=False)