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", dtype=torch.bfloat16 ) #Below code work for local ie,we must give the model name #model_path = ("../models/models--sshleifer--distilbart-cnn-12-6/snapshots/a4f8f3ea906ed274767e9906dbaede7531d660ff") #text_summary = pipeline( # "summarization", # model=model_path, # dtype=torch.bfloat16 #) # text='''Uncanny Tales was a Canadian science fiction pulp magazine edited by Melvin R. Colby that ran from November 1940 to September 1943. It was created in response to the wartime reduction of imports on British and American science-fiction pulp magazines. Initially it contained stories only from Canadian authors, with much of its contents supplied by Thomas P. Kelley, but within a few issues Colby began to obtain reprint rights to American stories from Donald A. Wollheim and Sam Moskowitz. Moskowitz reported that he found out via an acquaintance of Wollheim's that Colby had been persuaded by Wollheim to stop buying Moskowitz's submissions. The first issue was digest-sized, and was printed in green ink. For the first four issues the format remained unchanged, and almost all the stories were by Kelley or other Canadian writers. Paper shortages forced the magazine to shut down after less than three years. It is now extremely difficult to find printed copies. ''' # 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=6)], title="Text Summarizer", description="This application is used to summarize the provided input text ") demo.launch()