import torch import gradio as gr #import os #os.environ['TRANSFORMERS_CACHE'] = 'desired file path for model downloads' # 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 = "../models/models--sshleifer--distilbart-cnn-12-6/snapshots/a4f8f3ea906ed274767e9906dbaede7531d660ff" #text_summary = pipeline("summarization", # model=model_path, # torch_dtype=torch.bfloat16) # text = ''' # Microsoft Corporation is an American multinational corporation and technology company headquartered in Redmond, Washington. # Microsoft's best-known software products are the Windows line of operating systems, the Microsoft 365 suite of productivity applications, and the Edge web browser. # Its flagship hardware products are the Xbox video game consoles and the Microsoft Surface lineup of touchscreen personal computers. # Microsoft ranked No. 14 in the 2022 Fortune 500 rankings of the largest United States corporations by total revenue;[3] and it was the world's largest software maker by revenue in 2022 according to Forbes Global 2000. # ''' # 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="Text Summarizer!", description="THIS APPLICATION IS USED TO SUMMARIZE THE INPUT TEXT!" ) demo.launch()