File size: 1,279 Bytes
d76fd34
359bc68
d76fd34
 
1971ddf
93aaf1f
d76fd34
359bc68
1971ddf
 
 
 
 
 
 
 
 
 
 
d76fd34
1971ddf
 
d76fd34
1971ddf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155a9eb
 
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
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)]
                   )
demo.launch()