Spaces:
Sleeping
Sleeping
| import torch | |
| import gradio as gr | |
| from transformers import pipeline, BartTokenizer | |
| # Initialize the summarization pipeline with the chosen model | |
| text_summary = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6") | |
| # Define the summary function that uses the text_summary pipeline | |
| def summary(input): | |
| output = text_summary(input) # Perform summarization on the input text | |
| return output[0]['summary_text'] # Return the summarized text | |
| # Close any existing Gradio instances (useful for when running the script multiple times in an interactive environment) | |
| gr.close_all() | |
| # Example text for summarization | |
| example_text = """Elon Musk is a visionary entrepreneur known for founding and leading multiple groundbreaking companies, including Tesla, SpaceX, Neuralink, and The Boring Company. | |
| He has played a pivotal role in revolutionizing the electric vehicle industry, advancing space exploration with reusable rockets, and advocating for the development of sustainable energy solutions. | |
| Musk's ambitious goals, such as colonizing Mars and building a high-speed transportation system, continue to capture the world's attention and inspire innovation across various industries.""" | |
| # Create the Gradio interface | |
| demo = gr.Interface( | |
| fn=summary, # The function to be called for summarization | |
| inputs=gr.Textbox(label="Input text to summarize", lines=6), # Input textbox for the text to be summarized | |
| outputs=[gr.Textbox(label="Summarized text", lines=4)], # Output textbox for the summarized text | |
| title="Text Summarizer", # Title of the interface | |
| description="Summarize the text", # Description of the interface | |
| examples=[[example_text]] | |
| ) | |
| # Launch the Gradio interface | |
| demo.launch() | |