#python3 #build a text summarizer using hugging face and gradio import gradio as gr import pandas as pd import numpy as np import tensorflow as tf import transformers from transformers import TFAutoModel, AutoTokenizer model_class, tokenizer_class, pretrained_weights = (TFAutoModel, AutoTokenizer, 'bert-base-uncased') # Load pretrained model/tokenizer tokenizer = tokenizer_class.from_pretrained(pretrained_weights) model = model_class.from_pretrained(pretrained_weights) def get_summary(article): article_input_ids = tokenizer.encode(article, return_tensors='tf') summary_ids = model.generate(article_input_ids) summary_txt = tokenizer.decode(summary_ids[0], skip_special_tokens=True) return summary_txt def get_summary_gradio(article): return get_summary(article) iface = gr.Interface(get_summary_gradio, "textbox", "textbox", live=True, examples=[ ["The quick brown fox jumps over the lazy dog."], ["The world is a strange place. Sometimes, things are what they seem. But then, if you look closer, they can become something entirely different."], ["The sky is clear; the stars are twinkling. I'm going to bed now. Good night."], ["The president of the United States, and the president of the United Kingdom, have both been in the White House."], ["The president of the United States, and the president of the United Kingdom, have both been in the White House."] ]) if __name__ == "__main__": iface.launch()