Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import io
|
| 3 |
+
from IPython.display import Image, display, HTML
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import base64
|
| 6 |
+
from dotenv import load_dotenv, find_dotenv
|
| 7 |
+
import requests, json
|
| 8 |
+
from transformers import pipeline
|
| 9 |
+
|
| 10 |
+
get_completion = pipeline("summarization", model="shleifer/distilbart-cnn-12-6")
|
| 11 |
+
|
| 12 |
+
def summarize(input):
|
| 13 |
+
output = get_completion(input)
|
| 14 |
+
return output[0]['summary_text']
|
| 15 |
+
text = ('''The tower is 324 metres (1,063 ft) tall, about the same height
|
| 16 |
+
as an 81-storey building, and the tallest structure in Paris.
|
| 17 |
+
Its base is square, measuring 125 metres (410 ft) on each side.
|
| 18 |
+
During its construction, the Eiffel Tower surpassed the Washington
|
| 19 |
+
Monument to become the tallest man-made structure in the world,
|
| 20 |
+
a title it held for 41 years until the Chrysler Building
|
| 21 |
+
in New York City was finished in 1930. It was the first structure
|
| 22 |
+
to reach a height of 300 metres. Due to the addition of a broadcasting
|
| 23 |
+
aerial at the top of the tower in 1957, it is now taller than the
|
| 24 |
+
Chrysler Building by 5.2 metres (17 ft). Excluding transmitters, the
|
| 25 |
+
Eiffel Tower is the second tallest free-standing structure in France
|
| 26 |
+
after the Millau Viaduct.''')
|
| 27 |
+
|
| 28 |
+
get_completion(text)
|
| 29 |
+
import gradio as gr
|
| 30 |
+
|
| 31 |
+
def summarize(input):
|
| 32 |
+
output = get_completion(input)
|
| 33 |
+
return output[0]['summary_text']
|
| 34 |
+
|
| 35 |
+
gr.close_all()
|
| 36 |
+
demo = gr.Interface(fn=summarize,
|
| 37 |
+
inputs=[gr.Textbox(label="Text to summarize", lines=6)],
|
| 38 |
+
outputs=[gr.Textbox(label="Result", lines=3)],
|
| 39 |
+
title="Text summarization with distilbart-cnn",
|
| 40 |
+
description="Summarize any text using the `shleifer/distilbart-cnn-12-6` model under the hood!"
|
| 41 |
+
)
|
| 42 |
+
demo.launch()
|