awitecki commited on
Commit
07c8d3a
·
1 Parent(s): fbc0638

Super simple approach

Browse files
Files changed (3) hide show
  1. app.py +7 -31
  2. cnn_model.pkl → model.pkl +2 -2
  3. requirements.txt +4 -0
app.py CHANGED
@@ -1,42 +1,18 @@
1
  __all__ = ['learn', 'get_summary', 'intf']
2
 
3
  import gradio as gr
4
- from blurr.text.data.all import *
5
- from blurr.text.modeling.all import *
6
- from datasets import load_dataset
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
- pre_trained_model_name = "sshleifer/distilbart-cnn-6-6"
17
- hf_arch, hf_config, hf_tokenizer, hf_model = BlurrText().get_hf_objects(pre_trained_model_name, model_cls=BartForConditionalGeneration)
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='cnn_model.pkl')
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:4e23e9b040ee2022ccb52e2229135eb46b72c0bc2969a9016b1a4c02b6d3ffb2
3
- size 922705455
 
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