TextSummarizer / app.py
Sahibhim's picture
Create app.py
d3d1162 verified
import torch
import gradio as gr
# Use a pipeline as a high-level helper
from transformers import pipeline
text_summary = pipeline(
task="summarization",
model="sshleifer/distilbart-cnn-12-6",
torch_dtype=torch.bfloat16
)
# Local model path
# model_path = ("../Models/models--sshleifer--distilbart-xsum-12-6/snapshots/5b2e376c845c201ddc34ec0e55fd1ad9890ba5ee")
#
# # Summarization pipeline
# text_summary = pipeline(
# "summarization",
# model=model_path,
# torch_dtype=torch.bfloat16
# )
# Sample text
# text = '''Elon Reeve Musk FRS (/ˈiːlɒn/ EE-lon; born June 28, 1971) is a businessman,
# known for his leadership of Tesla, SpaceX, X (formerly Twitter), and the Department
# of Government Efficiency (DOGE). Musk has been the wealthiest person in the world
# since 2021; as of May 2025, Forbes estimates his net worth to be US$424.7 billion.'''
#
# # Run summarization
# 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="text",outputs="text")
demo=gr.Interface(fn=summary,inputs=[gr.Textbox(label="Input text to summarize",lines=6)],
outputs=[gr.Textbox(label="Summarized text",lines=4)],
title="@SahibhimGenAI Project 1: Text Summarizer",
description= "THIS APPLICATION WILL BE USED TO SUMMARIZE A TEXT TO SUMMARY")
demo.launch()