Spaces:
Sleeping
Sleeping
rjohansyah
commited on
Commit
•
4bbab27
1
Parent(s):
04025d8
Update input
Browse files- .gitignore +1 -0
- app.py +25 -9
- taskfile.yaml +0 -19
.gitignore
CHANGED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
__pycache__
|
app.py
CHANGED
@@ -1,15 +1,31 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
|
5 |
|
6 |
-
def
|
7 |
-
return "
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
outputs=["text"],
|
13 |
-
)
|
14 |
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
summarizer = pipeline(task="summarization", model="facebook/bart-large-cnn")
|
5 |
|
6 |
+
def fetch_record(record_url):
|
7 |
+
return "https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=387&q=80"
|
8 |
|
9 |
+
def summary_text(input_text: str, min_length: int = 30, max_length: int = 120):
|
10 |
+
summary = summarizer(input_text, max_length=max_length, min_length=min_length, do_sample=False)
|
11 |
+
return summary[0]['summary_text']
|
|
|
|
|
12 |
|
13 |
+
with gr.Blocks() as app:
|
14 |
+
gr.Markdown("# SLNSW - Text sumarisation from the input above")
|
15 |
+
gr.Markdown("Summarise long text description either by record URL or manual copy-and-paste.")
|
16 |
+
with gr.Row():
|
17 |
+
with gr.Column():
|
18 |
+
record_url = gr.Text(label="SL record URL", lines=5, info="The main URL of collections eg. https://collection.sl.nsw.gov.au/record/YdmdvKj9")
|
19 |
+
fetch_record_btn = gr.Button("Fetch URL")
|
20 |
+
with gr.Column():
|
21 |
+
input_text = gr.Text(label="Input text", lines=5, info="The manual input of long text", interactive=True)
|
22 |
+
summary_text_btn = gr.Button("Summary")
|
23 |
+
with gr.Row():
|
24 |
+
with gr.Column():
|
25 |
+
summary_text_txt = gr.Text(label="Summary", info="The summarised text")
|
26 |
+
|
27 |
+
fetch_record_btn.click(fn=fetch_record, inputs=[record_url], outputs=[input_text])
|
28 |
+
summary_text_btn.click(fn=summary_text, inputs=[input_text], outputs=[summary_text_txt], api_name="summary_text")
|
29 |
+
|
30 |
+
if __name__ == "__main__":
|
31 |
+
app.launch(server_name='0.0.0.0', ssl_verify=False)
|
taskfile.yaml
DELETED
@@ -1,19 +0,0 @@
|
|
1 |
-
version: "3"
|
2 |
-
env:
|
3 |
-
NAME: "slnsw-text-summary"
|
4 |
-
tasks:
|
5 |
-
setup-hf:
|
6 |
-
cmds:
|
7 |
-
- huggingface-cli repo create --type model -y $NAME
|
8 |
-
- huggingface-cli repo create --type space --space_sdk gradio -y $NAME
|
9 |
-
- huggingface-cli repo create --type dataset -y $NAME
|
10 |
-
setup-git:
|
11 |
-
cmds:
|
12 |
-
- git remote add hf-model https://huggingface.co/generaptor/$NAME
|
13 |
-
- git remote add hf-space https://huggingface.co/spaces/generaptor/$NAME
|
14 |
-
- git clone https://huggingface.co/datasets/generaptor/$NAME datasets
|
15 |
-
- git submodule add ./datasets hf-datasets
|
16 |
-
setup:
|
17 |
-
cmds:
|
18 |
-
- task: "setup-hf"
|
19 |
-
- task: "setup-git"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|