Super simple approach
Browse files- app.py +7 -31
- cnn_model.pkl → model.pkl +2 -2
- requirements.txt +4 -0
app.py
CHANGED
@@ -1,42 +1,18 @@
|
|
1 |
__all__ = ['learn', 'get_summary', 'intf']
|
2 |
|
3 |
import gradio as gr
|
4 |
-
|
5 |
-
|
6 |
-
from
|
7 |
-
from fastai.data.all import *
|
8 |
-
from fastai.callback.all import *
|
9 |
-
from fastai.learner import *
|
10 |
-
from fastai.optimizer import *
|
11 |
from transformers import *
|
12 |
-
import nltk
|
13 |
-
|
14 |
-
nltk.download('punkt', quiet=True)
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
summarization_metrics = {
|
19 |
-
"rouge": {
|
20 |
-
"compute_kwargs": {"rouge_types": ["rouge1", "rouge2", "rougeL", "rougeLsum"], "use_stemmer": True}, "returns": ["rouge1", "rouge2", "rougeL", "rougeLsum"],
|
21 |
-
},
|
22 |
-
"bertscore": {
|
23 |
-
"compute_kwargs": {"lang": "en"}, "returns": ["precision", "recall", "f1"]
|
24 |
-
}
|
25 |
-
}
|
26 |
-
translation_metrics = {
|
27 |
-
"bleu": {"returns": "bleu"},
|
28 |
-
"meteor": {"returns": "maeteor"},
|
29 |
-
"sacrebleu": {"returns": "score"},
|
30 |
-
}
|
31 |
-
|
32 |
-
model = BaseModelWrapper(hf_model)
|
33 |
-
learn_cbs = [BaseModelCallback]
|
34 |
-
fit_cbs = [Seq2SeqMetricsCallback(custom_metrics=summarization_metrics, calc_every="last_epoch")]
|
35 |
|
36 |
-
learn = load_learner(fname='
|
37 |
|
38 |
def get_summary(text, sequences_num):
|
39 |
-
return learn.blurr_summarize(text, num_return_sequences=sequences_num)
|
40 |
|
41 |
iface = gr.Interface(fn=get_summary, inputs=["text", gr.Number(value=5, label="sequences")], outputs="text")
|
42 |
iface.launch()
|
|
|
1 |
__all__ = ['learn', 'get_summary', 'intf']
|
2 |
|
3 |
import gradio as gr
|
4 |
+
import datasets
|
5 |
+
import pandas as pd
|
6 |
+
from fastai.text.all import *
|
|
|
|
|
|
|
|
|
7 |
from transformers import *
|
|
|
|
|
|
|
8 |
|
9 |
+
from blurr.text.data.all import *
|
10 |
+
from blurr.text.modeling.all import *
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
learn = load_learner(fname='model.pkl')
|
13 |
|
14 |
def get_summary(text, sequences_num):
|
15 |
+
return learn.blurr_summarize(text, early_stopping=True, num_beams=4, num_return_sequences=sequences_num)[0]
|
16 |
|
17 |
iface = gr.Interface(fn=get_summary, inputs=["text", gr.Number(value=5, label="sequences")], outputs="text")
|
18 |
iface.launch()
|
cnn_model.pkl → model.pkl
RENAMED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:05ff88c36679df1ede20bbd7623c7fb4d0e65ee0e8a5cbedf57979480bfca418
|
3 |
+
size 923727853
|
requirements.txt
CHANGED
@@ -1,2 +1,6 @@
|
|
1 |
bert_score
|
|
|
|
|
2 |
ohmeow-blurr
|
|
|
|
|
|
1 |
bert_score
|
2 |
+
datasets
|
3 |
+
fastai
|
4 |
ohmeow-blurr
|
5 |
+
sacremoses
|
6 |
+
transformers
|