TextSummarizer / app.py
Sam082003's picture
Create app.py
9834f52 verified
import gradio as gr
import torch
# Use a pipeline as a high-level helper
from transformers import pipeline
text_summary = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6", torch_dtype=torch.bfloat16)
#model_path="../model/models--sshleifer--distilbart-cnn-12-6/snapshots/a4f8f3ea906ed274767e9906dbaede7531d660ff"
#text_summary = pipeline("summarization", model=model_path,torch_dtype=torch.bfloat16)
'''text="A member of the wealthy South African Musk family, Musk was born in Pretoria and briefly attended the University of Pretoria before immigrating to Canada at age 18, acquiring citizenship through his Canadian-born mother. Two years later, he matriculated at Queen's University at Kingston in Canada. Musk later transferred to the University of Pennsylvania and received bachelor's degrees in economics and physics. He moved to California in 1995 to attend Stanford University, but dropped out after two days and, with his brother Kimbal, co-founded online city guide software company Zip2. The startup was acquired by Compaq for $307 million in 1999. That same year, Musk co-founded X.com, a direct bank. X.com merged with Confinity in 2000 to form PayPal. In October 2002, eBay acquired PayPal for $1.5 billion. Using $100 million of the money he made from the sale of PayPal, Musk founded SpaceX, a spaceflight services company, in 2002.He became the company's chairman and product architect, assuming the position of CEO in 2008. In 2006, Musk helped create SolarCity, a solar-energy company that was acquired by Tesla in 2016"
print(text_summary(text))'''
def summary(input):
output=text_summary(input)
return output[0]['summary_text']
gr.close_all()
demo = gr.Interface(fn=summary,
inputs=[gr.Textbox(label="Input text to summarize",lines=6)],
outputs=[gr.Textbox(label="Summarized text",lines=4)],
title="Project 1: Text Summarizer",
description="THIS APPLICATION WILL BE USED TO SUMMARIZE THE TEXT")
demo.launch()