Spaces:
Sleeping
Sleeping
Update app.py
Browse filesAdd docstring and some Aesthetic changes to the UI
app.py
CHANGED
|
@@ -2,18 +2,56 @@ import gradio as gr
|
|
| 2 |
import spaces
|
| 3 |
from transformers import pipeline
|
| 4 |
|
|
|
|
| 5 |
get_completion = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6", device=0)
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
@spaces.GPU(duration=120)
|
| 8 |
-
def summarize(input):
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
return output[0]['summary_text']
|
| 11 |
-
|
|
|
|
| 12 |
gr.close_all()
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
inputs=[gr.Textbox(label="Text to Summarize", lines=6)],
|
| 15 |
-
outputs=[gr.Textbox(label="Result", lines=3)]
|
| 16 |
-
title="Text Summarization with distilbart-cnn",
|
| 17 |
-
description="Summarize any text using the `sshleifer/distilbart-cnn-12-6` model under the hood"
|
| 18 |
)
|
| 19 |
demo.launch()
|
|
|
|
| 2 |
import spaces
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
+
# Initialize Model
|
| 6 |
get_completion = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6", device=0)
|
| 7 |
|
| 8 |
+
|
| 9 |
+
# @spaces.GPU(duration=120)
|
| 10 |
+
# def summarize(input):
|
| 11 |
+
# output = get_completion(input)
|
| 12 |
+
# return output[0]['summary_text']
|
| 13 |
+
|
| 14 |
@spaces.GPU(duration=120)
|
| 15 |
+
def summarize(input: str) -> str:
|
| 16 |
+
"""
|
| 17 |
+
Summarize the given input text using the sshleifer/distilbart-cnn-12-6 model.
|
| 18 |
+
|
| 19 |
+
Args:
|
| 20 |
+
input (str): The text to be summarized.
|
| 21 |
+
|
| 22 |
+
Returns:
|
| 23 |
+
str: The summarized version of the input text.
|
| 24 |
+
"""
|
| 25 |
+
output: List[Dict[str, str]] = get_completion(input)
|
| 26 |
return output[0]['summary_text']
|
| 27 |
+
|
| 28 |
+
|
| 29 |
gr.close_all()
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
####### GRADIO APP #######
|
| 33 |
+
title = """<h1 id="title"> Text Summarization </h1>"""
|
| 34 |
+
|
| 35 |
+
description = """
|
| 36 |
+
Summarize any text using the `sshleifer/distilbart-cnn-12-6` model under the hood
|
| 37 |
+
|
| 38 |
+
- The model used for Summarizing Text [DISTILBART-12-6-CNN](https://huggingface.co/sshleifer/distilbart-cnn-12-6).
|
| 39 |
+
"""
|
| 40 |
+
|
| 41 |
+
css = '''
|
| 42 |
+
h1#title {
|
| 43 |
+
text-align: center;
|
| 44 |
+
}
|
| 45 |
+
'''
|
| 46 |
+
|
| 47 |
+
theme = gr.themes.Soft()
|
| 48 |
+
demo = gr.Blocks(css=css, theme=theme)
|
| 49 |
+
|
| 50 |
+
with demo:
|
| 51 |
+
gr.Markdown(title)
|
| 52 |
+
gr.Markdown(description)
|
| 53 |
+
interface = gr.Interface(fn=summarize,
|
| 54 |
inputs=[gr.Textbox(label="Text to Summarize", lines=6)],
|
| 55 |
+
outputs=[gr.Textbox(label="Result", lines=3)]
|
|
|
|
|
|
|
| 56 |
)
|
| 57 |
demo.launch()
|