Gameel tomsoderlund commited on
Commit
9a4b212
·
0 Parent(s):

Duplicate from tomsoderlund/text-summarizer

Browse files

Co-authored-by: Tom Söderlund <[email protected]>

Files changed (5) hide show
  1. .gitattributes +34 -0
  2. .gitignore +1 -0
  3. README.md +21 -0
  4. app.py +61 -0
  5. requirements.txt +171 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ env/
README.md ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Text Summarizer
3
+ emoji: 📰
4
+ colorFrom: indigo
5
+ colorTo: purple
6
+ sdk: gradio
7
+ sdk_version: 3.14.0
8
+ python_version: 3.9.13
9
+ app_file: app.py
10
+ pinned: false
11
+ license: openrail
12
+ models:
13
+ - facebook/bart-large-cnn
14
+ - Vamsi/T5_Paraphrase_Paws
15
+ duplicated_from: tomsoderlund/text-summarizer
16
+ ---
17
+
18
+ # Text shortener/paraphraser
19
+
20
+ - Shortening texts using `facebook/bart-large-cnn`
21
+ - Paraphrasing texts using `Vamsi/T5_Paraphrase_Paws`
app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio
2
+ import torch
3
+ from transformers import pipeline, AutoTokenizer, AutoModelForSeq2SeqLM
4
+
5
+ def shorten_text(text, min_length, max_length):
6
+ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
7
+ short_text = text[:1024]
8
+ summary = summarizer(short_text, max_length, min_length, do_sample=False)
9
+ print("** summary", summary)
10
+ return summary[0]["summary_text"]
11
+
12
+ def paraphrase_text(text, min_length, max_length):
13
+ tokenizer = AutoTokenizer.from_pretrained("Vamsi/T5_Paraphrase_Paws")
14
+ model = AutoModelForSeq2SeqLM.from_pretrained("Vamsi/T5_Paraphrase_Paws")
15
+ device = "cuda" if torch.cuda.is_available() else "cpu"
16
+ text_instruction = "paraphrase: " + text + " </s>"
17
+ encoding = tokenizer.encode_plus(text_instruction, padding="longest", return_tensors="pt")
18
+ input_ids, attention_masks = encoding["input_ids"].to(device), encoding["attention_mask"].to(device)
19
+ outputs = model.generate(
20
+ input_ids=input_ids, attention_mask=attention_masks,
21
+ max_length=max_length,
22
+ do_sample=True,
23
+ top_k=120,
24
+ top_p=0.95,
25
+ early_stopping=True,
26
+ num_return_sequences=5
27
+ )
28
+ line = tokenizer.decode(outputs[0], skip_special_tokens=True, clean_up_tokenization_spaces=True)
29
+ print("** outputs", len(outputs), line)
30
+ return line
31
+
32
+ def modify_text(mode, text, min_length, max_length):
33
+ if mode == "shorten":
34
+ return shorten_text(text, min_length, max_length)
35
+ else:
36
+ return paraphrase_text(text, min_length, max_length)
37
+
38
+ gradio_interface = gradio.Interface(
39
+ fn=modify_text,
40
+ inputs=[
41
+ gradio.Radio(["shorten", "paraphrase"], label="Mode"),
42
+ "text",
43
+ gradio.Slider(5, 200, value=30, label="Min length"),
44
+ gradio.Slider(5, 500, value=130, label="Max length")
45
+ ],
46
+ outputs="text",
47
+ examples=[
48
+ ["shorten",
49
+ """A beautiful golden sun is setting. The sky is on fire. A large neon sign rises into shot. It rests on top of a skyscraper and fills the frame. The building is neither past nor future in design but a bit of both.
50
+
51
+ Slowly we pan downwards revealing the city that spreads below. A glittering conglomeration of elevated transport tubes, smaller square buildings which are merely huge, with, here and there, the comparatively minuscule relics of previous ages of architecture, pavement level awnings suggesting restaurants and shops. Transparent tubes carry whizzing transport cages past us. An elevated highway carrying traffic composed primarily of large transport lorries passes through frame.
52
+
53
+ As we descend, the sunlight is blocked out and street lights & neon signs take over as illumination. Eventually we reach the upper levels of a plush shopping precinct.
54
+ Xmas decorations are everywhere. People are busy buying, ogling, discussing, choosing wisely from the goodies on display. Shoppers are going by laden with superbly packaged goods. The shop windows are full of elaborately boxed and be-ribboned who-knows-what. In one window is a bank of TV sets on the great majority of the screens is the face of Mr. Helpmann the Deputy Minister of Information. He is being interviewed. No-one bothers to listen to Helpmann.""",
55
+ 30, 130]
56
+ ],
57
+ title="Text shortener/paraphraser",
58
+ description="Shortening texts using `facebook/bart-large-cnn`, paraphrasing texts using `Vamsi/T5_Paraphrase_Paws`.",
59
+ article="© Tom Söderlund 2022"
60
+ )
61
+ gradio_interface.launch()
requirements.txt ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiohttp==3.8.3
2
+ aiosignal==1.2.0
3
+ anyio==3.6.2
4
+ appnope==0.1.3
5
+ argon2-cffi==21.3.0
6
+ argon2-cffi-bindings==21.2.0
7
+ asttokens==2.0.8
8
+ async-timeout==4.0.2
9
+ attrs==22.1.0
10
+ Babel==2.10.3
11
+ backcall==0.2.0
12
+ bcrypt==4.0.1
13
+ beautifulsoup4==4.11.1
14
+ bleach==5.0.1
15
+ blis==0.7.9
16
+ catalogue==2.0.8
17
+ certifi==2022.6.15
18
+ cffi==1.15.1
19
+ charset-normalizer==2.1.0
20
+ click==8.1.3
21
+ confection==0.0.3
22
+ contourpy==1.0.5
23
+ cryptography==38.0.4
24
+ cycler==0.11.0
25
+ cymem==2.0.7
26
+ datasets==2.6.1
27
+ debugpy==1.6.3
28
+ decorator==5.1.1
29
+ defusedxml==0.7.1
30
+ dill==0.3.5.1
31
+ entrypoints==0.4
32
+ executing==1.1.1
33
+ fastai==2.7.9
34
+ fastapi==0.88.0
35
+ fastbook==0.0.28
36
+ fastcore==1.5.27
37
+ fastdownload==0.0.7
38
+ fastjsonschema==2.16.2
39
+ fastprogress==1.0.3
40
+ ffmpy==0.3.0
41
+ filelock==3.8.0
42
+ Flask==2.2.2
43
+ fonttools==4.38.0
44
+ frozenlist==1.3.1
45
+ fsspec==2022.10.0
46
+ gradio==3.12.0
47
+ graphviz==0.20.1
48
+ gunicorn==20.1.0
49
+ h11==0.12.0
50
+ httpcore==0.15.0
51
+ httpx==0.23.1
52
+ huggingface-hub==0.10.1
53
+ idna==3.3
54
+ importlib-metadata==5.0.0
55
+ ipykernel==6.16.1
56
+ ipython==8.5.0
57
+ ipython-genutils==0.2.0
58
+ ipywidgets==8.0.2
59
+ itsdangerous==2.1.2
60
+ jedi==0.18.1
61
+ Jinja2==3.1.2
62
+ joblib==1.2.0
63
+ json5==0.9.10
64
+ jsonschema==4.16.0
65
+ jupyter-server==1.21.0
66
+ jupyter_client==7.4.3
67
+ jupyter_core==4.11.2
68
+ jupyterlab-pygments==0.2.2
69
+ jupyterlab-widgets==3.0.3
70
+ jupyterlab_server==2.16.1
71
+ kiwisolver==1.4.4
72
+ langcodes==3.3.0
73
+ linkify-it-py==1.0.3
74
+ markdown-it-py==2.1.0
75
+ MarkupSafe==2.1.1
76
+ matplotlib==3.6.1
77
+ matplotlib-inline==0.1.6
78
+ mdit-py-plugins==0.3.1
79
+ mdurl==0.1.2
80
+ mistune==2.0.4
81
+ multidict==6.0.2
82
+ multiprocess==0.70.13
83
+ murmurhash==1.0.9
84
+ nbclassic==0.4.5
85
+ nbclient==0.7.0
86
+ nbconvert==7.2.2
87
+ nbformat==5.7.0
88
+ nest-asyncio==1.5.6
89
+ notebook==6.5.1
90
+ notebook_shim==0.2.0
91
+ numpy==1.23.4
92
+ orjson==3.8.2
93
+ packaging==21.3
94
+ pandas==1.5.1
95
+ pandocfilters==1.5.0
96
+ paramiko==2.12.0
97
+ parso==0.8.3
98
+ pathy==0.6.2
99
+ pexpect==4.8.0
100
+ pickleshare==0.7.5
101
+ Pillow==9.2.0
102
+ preshed==3.0.8
103
+ prometheus-client==0.15.0
104
+ prompt-toolkit==3.0.31
105
+ protobuf==3.20.0
106
+ psutil==5.9.3
107
+ psycopg2==2.9.5
108
+ ptyprocess==0.7.0
109
+ pure-eval==0.2.2
110
+ pyarrow==9.0.0
111
+ pycparser==2.21
112
+ pycryptodome==3.16.0
113
+ pydantic==1.10.2
114
+ pydub==0.25.1
115
+ Pygments==2.13.0
116
+ PyNaCl==1.5.0
117
+ pyparsing==3.0.9
118
+ pyrsistent==0.18.1
119
+ python-dateutil==2.8.2
120
+ python-dotenv==0.20.0
121
+ python-multipart==0.0.5
122
+ pytz==2022.5
123
+ PyYAML==6.0
124
+ pyzmq==24.0.1
125
+ regex==2022.9.13
126
+ requests==2.28.1
127
+ responses==0.18.0
128
+ rfc3986==1.5.0
129
+ scikit-learn==1.1.2
130
+ scipy==1.9.3
131
+ Send2Trash==1.8.0
132
+ sentencepiece==0.1.97
133
+ six==1.16.0
134
+ smart-open==5.2.1
135
+ sniffio==1.3.0
136
+ soupsieve==2.3.2.post1
137
+ spacy==3.4.2
138
+ spacy-legacy==3.0.10
139
+ spacy-loggers==1.0.3
140
+ srsly==2.4.5
141
+ stack-data==0.5.1
142
+ starlette==0.22.0
143
+ stripe==3.5.0
144
+ terminado==0.16.0
145
+ thinc==8.1.5
146
+ threadpoolctl==3.1.0
147
+ tinycss2==1.2.1
148
+ tokenizers==0.13.1
149
+ tomli==2.0.1
150
+ torch==1.12.1
151
+ torchvision==0.13.1
152
+ tornado==6.2
153
+ tqdm==4.64.1
154
+ traitlets==5.5.0
155
+ transformers==4.23.1
156
+ typer==0.4.2
157
+ typing_extensions==4.4.0
158
+ uc-micro-py==1.0.1
159
+ urllib3==1.26.10
160
+ uvicorn==0.20.0
161
+ wasabi==0.10.1
162
+ wcwidth==0.2.5
163
+ webencodings==0.5.1
164
+ websocket-client==1.4.1
165
+ websockets==10.4
166
+ Werkzeug==2.2.2
167
+ widgetsnbextension==4.0.3
168
+ XlsxWriter==3.0.3
169
+ xxhash==3.1.0
170
+ yarl==1.8.1
171
+ zipp==3.9.0