Spaces:
Runtime error
Runtime error
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.float16) | |
# # Use a model directly | |
# model_path = "C:/Users/me/.cache/huggingface/hub/models--sshleifer--distilbart-cnn-12-6/snapshots/a4f8f3ea906ed274767e9906dbaede7531d660ff" | |
# text_summary = pipeline("summarization", model=model_path,torch_dtype=torch.float16) | |
# text = '''Donald John Trump (born June 14, 1946) is an American politician, businessman, and media personality who has been the 47th and current president of the United States since 2025. A member of the Republican Party, he previously served as the 45th president from 2017 to 2021.Trump won the 2016 presidential election. His immigration policy included a temporary travel ban targeting refugees and nationals of certain Muslim-majority countries, and expanding the U.S.–Mexico border wall; he also briefly implemented a family separation policy. He rolled back more than 100 environmental policies and regulations, signed the Tax Cuts and Jobs Act of 2017, initiated a trade war with China in 2018, and withdrew the U.S. from international agreements on climate, trade, and the nuclear program of Iran. Trump was the first sitting U.S. president to enter North Korea; he met with Kim Jong Un, but they did not reach agreement on denuclearization. He nominated three Supreme Court justices in his first term. Trump's response to the COVID-19 pandemic downplayed its severity, contradicted guidance from international public health bodies, and included the CARES Act economic stimulus. He was impeached in 2019 for abuse of power and obstruction of Congress, and in 2021 for incitement of insurrection; the Senate acquitted him in both cases. After his first term, scholars and historians ranked Trump as one of the worst presidents in American history.''' | |
# print(text_summary(text)) | |
def summary(input_text): | |
return text_summary(input_text)[0]['summary_text'] | |
gr.close_all() | |
demo = gr.Interface(fn=summary, inputs=[gr.Textbox(label="Input text to summarize",lines=20)], outputs=[gr.Textbox(label="Input text to summarize",lines=6)], title="Text Summarization", description="Summarize text using the DistilBART model.") | |
demo.launch(); |