File size: 2,195 Bytes
d76fd34
359bc68
d76fd34
 
1971ddf
93aaf1f
d76fd34
359bc68
1971ddf
 
 
 
 
 
 
 
 
 
 
d76fd34
1971ddf
 
d76fd34
1971ddf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155a9eb
3921910
 
 
 
 
 
 
81592a1
d76fd34
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import gradio as gr
import spaces
from transformers import pipeline

# Initialize Model
get_completion = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6", device=0)

@spaces.GPU(duration=120)
def summarize(input: str) -> str:
    """
    Summarize the given input text using the sshleifer/distilbart-cnn-12-6 model.

    Args:
        input (str): The text to be summarized.

    Returns:
        str: The summarized version of the input text.
    """
    output: List[Dict[str, str]] = get_completion(input)
    return output[0]['summary_text']


gr.close_all()


####### GRADIO APP #######
title = """<h1 id="title"> Text Summarization </h1>"""

description = """
Summarize any text using the `sshleifer/distilbart-cnn-12-6` model under the hood

- The model used for Summarizing Text [DISTILBART-12-6-CNN](https://huggingface.co/sshleifer/distilbart-cnn-12-6).
"""

css = '''
h1#title {
  text-align: center;
}
'''

theme = gr.themes.Soft()
demo = gr.Blocks(css=css, theme=theme)

with demo:
  gr.Markdown(title)
  gr.Markdown(description)
  interface = gr.Interface(fn=summarize, 
                    inputs=[gr.Textbox(label="Text to Summarize", lines=15)], 
                    outputs=[gr.Textbox(label="Result", lines=7)],
                    examples=["""Artificial Intelligence (AI) has been a rapidly growing field over the past decade, transforming various industries such as healthcare, finance, and transportation. 
                                 One of the key areas of AI research is machine learning, which focuses on developing algorithms that allow computers to learn from and make decisions based on data. 
                                 Recent advancements in deep learning, a subset of machine learning, have led to significant breakthroughs in image and speech recognition, natural language processing, and autonomous systems. 
                                 As AI continues to evolve, it is expected to play an increasingly important role in solving complex problems, enhancing productivity, and driving innovation across different sectors."""
                             ],
                    cache_examples=True
                   )
demo.launch()