Spaces:
Sleeping
Sleeping
alyxx commited on
Commit ·
59cfb08
1
Parent(s): 12270b3
update march14
Browse files- app.py +41 -0
- requirements.txt +5 -0
app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
# the summarization pipeline
|
| 5 |
+
sum_pipeline = pipeline(
|
| 6 |
+
"summarization",
|
| 7 |
+
model="kaiku03/Summarization_story"
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
# function for the gradio app
|
| 11 |
+
def fn_summarization(prompt):
|
| 12 |
+
return sum_pipeline(prompt)[0]['summary_text']
|
| 13 |
+
|
| 14 |
+
# gradio app
|
| 15 |
+
# Define example inputs and outputs
|
| 16 |
+
examples = ["""One day a rabbit was boasting about how fast he could run.
|
| 17 |
+
He was laughing at the turtle for being so slow.
|
| 18 |
+
Much to the rabbit’s surprise, the turtle challenged him to a race.
|
| 19 |
+
The rabbit thought this was a good joke and accepted the challenge.
|
| 20 |
+
The fox was to be the umpire of the race. As the race began,
|
| 21 |
+
the rabbit raced way ahead of the turtle, just like everyone thought.
|
| 22 |
+
The rabbit got to the halfway point and could not see the turtle anywhere.
|
| 23 |
+
He was hot and tired and decided to stop and take a short nap.
|
| 24 |
+
Even if the turtle passed him, he would be able to race to the finish line ahead of him.
|
| 25 |
+
All this time the turtle kept walking step by step by step. He never quit no matter how hot or tired he got.
|
| 26 |
+
He just kept going. However, the rabbit slept longer than he had thought and woke up.
|
| 27 |
+
He could not see the turtle anywhere! He went at full speed to the finish line but found the turtle there waiting for him."""]
|
| 28 |
+
|
| 29 |
+
iface = gr.Interface(
|
| 30 |
+
fn=fn_summarization,
|
| 31 |
+
inputs='text',
|
| 32 |
+
outputs=gr.Textbox(label="Summary"),
|
| 33 |
+
examples=[
|
| 34 |
+
[ex] for ex in examples
|
| 35 |
+
],
|
| 36 |
+
title='Text Summarization',
|
| 37 |
+
description='Summarize your text using Kaiku03/Summarization_story model.',
|
| 38 |
+
article='All done by Kaiku'
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
iface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers
|
| 2 |
+
gradio==3.45
|
| 3 |
+
torch
|
| 4 |
+
sentencepiece
|
| 5 |
+
nltk
|