Kush1211 commited on
Commit
3987de7
·
verified ·
1 Parent(s): c22b43a

Upload 10 files

Browse files
app.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline, AutoModelForSeq2SeqLM, AutoTokenizer
2
+ import gradio as gr
3
+ import re
4
+
5
+ model_link = "text_summary_model"
6
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_link)
7
+ tokenizer = AutoTokenizer.from_pretrained(model_link)
8
+
9
+ pipe = pipeline('summarization', model=model, tokenizer=tokenizer)
10
+ gen_kwargs = {'length_penalty': 0.8, 'num_beams': 8, "min_length": 30}
11
+
12
+
13
+ def dummy_summarize(text):
14
+ text = clean_text(text)
15
+ return pipe(text, **gen_kwargs)[0]['summary_text']
16
+
17
+
18
+ def clean_text(text):
19
+ # Remove Byte Order Marks (BOM)
20
+ text = text.replace('\ufeff', '')
21
+ # Replace \n with a space
22
+ text = text.replace('\n', ' ')
23
+ # Replace \r with a space
24
+ text = text.replace('\r', ' ')
25
+ # Remove backslashes
26
+ text = text.replace('\\', '')
27
+ # Remove Non-ASCII characters
28
+ text = re.sub(r'[^\x00-\x7F]+', '', text)
29
+ # Remove Non-printable characters
30
+ text = re.sub(r'[\x00-\x1F\x7F-\x9F]', '', text)
31
+ # Normalize whitespace
32
+ text = ' '.join(text.split())
33
+ return text
34
+
35
+
36
+ # Custom HTML and CSS for the title and theme
37
+ title_html = """
38
+ <h1 style="font-size: 40px; text-align: center; color: white;">Text Summarization</h1>
39
+ <p style="text-align: center; color: white; font-size:20px">Enter text to summarize it.</p>
40
+ """
41
+
42
+ css = """
43
+ body {
44
+ background-color: #007BFF;
45
+ color: white;
46
+ }
47
+
48
+ .gr-textbox textarea {
49
+ background-color: #0056b3;
50
+ color: white;
51
+ border: 2px solid white;
52
+ }
53
+
54
+ .gr-button {
55
+ background-color: #0056b3;
56
+ color: white;
57
+ border: 2px solid white;
58
+ }
59
+
60
+ .gr-button:hover {
61
+ background-color: #004080;
62
+ }
63
+
64
+ .gr-textbox input {
65
+ background-color: #0056b3;
66
+ color: white;
67
+ border: 2px solid white;
68
+ }
69
+ """
70
+
71
+ # Create a Gradio interface with large input and output textboxes
72
+ interface = gr.Interface(
73
+ fn=dummy_summarize,
74
+ inputs=gr.Textbox(lines=15, placeholder="Enter text here..."),
75
+ outputs=gr.Textbox(lines=15, placeholder="Summary will appear here..."),
76
+ description=title_html,
77
+ theme="compact", # Use compact theme to reduce padding
78
+ css=css
79
+ )
80
+
81
+ # Launch the interface
82
+ interface.launch()
text_summary_model/config.json ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "facebook/bart-large-cnn",
3
+ "_num_labels": 3,
4
+ "activation_dropout": 0.0,
5
+ "activation_function": "gelu",
6
+ "add_final_layer_norm": false,
7
+ "architectures": [
8
+ "BartForConditionalGeneration"
9
+ ],
10
+ "attention_dropout": 0.0,
11
+ "bos_token_id": 0,
12
+ "classif_dropout": 0.0,
13
+ "classifier_dropout": 0.0,
14
+ "d_model": 1024,
15
+ "decoder_attention_heads": 16,
16
+ "decoder_ffn_dim": 4096,
17
+ "decoder_layerdrop": 0.0,
18
+ "decoder_layers": 12,
19
+ "decoder_start_token_id": 2,
20
+ "dropout": 0.1,
21
+ "early_stopping": true,
22
+ "encoder_attention_heads": 16,
23
+ "encoder_ffn_dim": 4096,
24
+ "encoder_layerdrop": 0.0,
25
+ "encoder_layers": 12,
26
+ "eos_token_id": 2,
27
+ "force_bos_token_to_be_generated": true,
28
+ "forced_bos_token_id": 0,
29
+ "forced_eos_token_id": 2,
30
+ "gradient_checkpointing": false,
31
+ "id2label": {
32
+ "0": "LABEL_0",
33
+ "1": "LABEL_1",
34
+ "2": "LABEL_2"
35
+ },
36
+ "init_std": 0.02,
37
+ "is_encoder_decoder": true,
38
+ "label2id": {
39
+ "LABEL_0": 0,
40
+ "LABEL_1": 1,
41
+ "LABEL_2": 2
42
+ },
43
+ "length_penalty": 2.0,
44
+ "max_length": 142,
45
+ "max_position_embeddings": 1024,
46
+ "min_length": 56,
47
+ "model_type": "bart",
48
+ "no_repeat_ngram_size": 3,
49
+ "normalize_before": false,
50
+ "num_beams": 4,
51
+ "num_hidden_layers": 12,
52
+ "output_past": true,
53
+ "pad_token_id": 1,
54
+ "prefix": " ",
55
+ "scale_embedding": false,
56
+ "task_specific_params": {
57
+ "summarization": {
58
+ "early_stopping": true,
59
+ "length_penalty": 2.0,
60
+ "max_length": 142,
61
+ "min_length": 56,
62
+ "no_repeat_ngram_size": 3,
63
+ "num_beams": 4
64
+ }
65
+ },
66
+ "torch_dtype": "float32",
67
+ "transformers_version": "4.42.4",
68
+ "use_cache": true,
69
+ "vocab_size": 50264
70
+ }
text_summary_model/generation_config.json ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 0,
4
+ "decoder_start_token_id": 2,
5
+ "early_stopping": true,
6
+ "eos_token_id": 2,
7
+ "forced_bos_token_id": 0,
8
+ "forced_eos_token_id": 2,
9
+ "length_penalty": 2.0,
10
+ "max_length": 142,
11
+ "min_length": 56,
12
+ "no_repeat_ngram_size": 3,
13
+ "num_beams": 4,
14
+ "pad_token_id": 1,
15
+ "transformers_version": "4.42.4"
16
+ }
text_summary_model/merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
text_summary_model/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e42541a15e2f35e73d3fb8ad9240f5c3c130bdc365e7378265b9314a886cda5f
3
+ size 1625422896
text_summary_model/special_tokens_map.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<s>",
3
+ "cls_token": "<s>",
4
+ "eos_token": "</s>",
5
+ "mask_token": {
6
+ "content": "<mask>",
7
+ "lstrip": true,
8
+ "normalized": true,
9
+ "rstrip": false,
10
+ "single_word": false
11
+ },
12
+ "pad_token": "<pad>",
13
+ "sep_token": "</s>",
14
+ "unk_token": "<unk>"
15
+ }
text_summary_model/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
text_summary_model/tokenizer_config.json ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "added_tokens_decoder": {
4
+ "0": {
5
+ "content": "<s>",
6
+ "lstrip": false,
7
+ "normalized": true,
8
+ "rstrip": false,
9
+ "single_word": false,
10
+ "special": true
11
+ },
12
+ "1": {
13
+ "content": "<pad>",
14
+ "lstrip": false,
15
+ "normalized": true,
16
+ "rstrip": false,
17
+ "single_word": false,
18
+ "special": true
19
+ },
20
+ "2": {
21
+ "content": "</s>",
22
+ "lstrip": false,
23
+ "normalized": true,
24
+ "rstrip": false,
25
+ "single_word": false,
26
+ "special": true
27
+ },
28
+ "3": {
29
+ "content": "<unk>",
30
+ "lstrip": false,
31
+ "normalized": true,
32
+ "rstrip": false,
33
+ "single_word": false,
34
+ "special": true
35
+ },
36
+ "50264": {
37
+ "content": "<mask>",
38
+ "lstrip": true,
39
+ "normalized": true,
40
+ "rstrip": false,
41
+ "single_word": false,
42
+ "special": true
43
+ }
44
+ },
45
+ "bos_token": "<s>",
46
+ "clean_up_tokenization_spaces": true,
47
+ "cls_token": "<s>",
48
+ "eos_token": "</s>",
49
+ "errors": "replace",
50
+ "mask_token": "<mask>",
51
+ "model_max_length": 1000000000000000019884624838656,
52
+ "pad_token": "<pad>",
53
+ "sep_token": "</s>",
54
+ "tokenizer_class": "BartTokenizer",
55
+ "trim_offsets": true,
56
+ "unk_token": "<unk>"
57
+ }
text_summary_model/training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f2bf0ae5f5b15c697a57a75f391c841ce31ad72cb0cf57c5629be83c616650a9
3
+ size 5112
text_summary_model/vocab.json ADDED
The diff for this file is too large to render. See raw diff