File size: 1,731 Bytes
2931b84
 
c2f9542
2931b84
c2f9542
 
2931b84
c2f9542
 
 
 
2931b84
c2f9542
2931b84
 
4a4b811
 
 
 
 
c2f9542
 
 
c986969
c2f9542
c986969
c2f9542
4a4b811
 
c2f9542
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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()