Spaces:
Sleeping
Sleeping
Upload 10 files
Browse files- app.py +35 -0
- model.py +9 -0
- summarizer_model/config.json +69 -0
- summarizer_model/generation_config.json +16 -0
- summarizer_model/merges.txt +0 -0
- summarizer_model/special_tokens_map.json +15 -0
- summarizer_model/tokenizer.json +0 -0
- summarizer_model/tokenizer_config.json +58 -0
- summarizer_model/vocab.json +0 -0
- tempCodeRunnerFile.python +12 -0
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
st.set_page_config(page_title="AI TL;DR Tool", page_icon="📝")
|
| 5 |
+
@st.cache_resource
|
| 6 |
+
def load_summarizer():
|
| 7 |
+
return pipeline("summarization", model="./summarizer_model")
|
| 8 |
+
|
| 9 |
+
summarizer = load_summarizer()
|
| 10 |
+
|
| 11 |
+
st.title("Automated Text Summarizer")
|
| 12 |
+
st.subheader("Generate a 2-3 sentence summary of long articles or legal docs.")
|
| 13 |
+
|
| 14 |
+
text_to_summarize = st.text_area("Paste your long text here:", height=300)
|
| 15 |
+
|
| 16 |
+
with st.sidebar:
|
| 17 |
+
st.header("Settings")
|
| 18 |
+
max_len = st.slider("Max Summary Length", 30, 150, 75)
|
| 19 |
+
min_len = st.slider("Min Summary Length", 10, 50, 25)
|
| 20 |
+
|
| 21 |
+
if st.button("Generate TL;DR"):
|
| 22 |
+
if text_to_summarize.strip():
|
| 23 |
+
with st.spinner("Analyzing and condensing..."):
|
| 24 |
+
output = summarizer(
|
| 25 |
+
text_to_summarize,
|
| 26 |
+
max_length=max_len,
|
| 27 |
+
min_length=min_len,
|
| 28 |
+
do_sample=False
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
st.success("Summary Generated")
|
| 32 |
+
st.write(f"### Result:")
|
| 33 |
+
st.write(output[0]['summary_text'])
|
| 34 |
+
else:
|
| 35 |
+
st.warning("Please paste some text first!")
|
model.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
|
| 3 |
+
model_name = "facebook/bart-large-cnn"
|
| 4 |
+
summarizer = pipeline("summarization", model=model_name)
|
| 5 |
+
|
| 6 |
+
# Save the model and tokenizer to a local directory
|
| 7 |
+
# This is the Hugging Face standard for 'pickling' a model
|
| 8 |
+
summarizer.save_pretrained("./summarizer_model")
|
| 9 |
+
print("Model saved successfully to ./summarizer_model")
|
summarizer_model/config.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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": null,
|
| 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_eos_token_id": 2,
|
| 29 |
+
"gradient_checkpointing": false,
|
| 30 |
+
"id2label": {
|
| 31 |
+
"0": "LABEL_0",
|
| 32 |
+
"1": "LABEL_1",
|
| 33 |
+
"2": "LABEL_2"
|
| 34 |
+
},
|
| 35 |
+
"init_std": 0.02,
|
| 36 |
+
"is_encoder_decoder": true,
|
| 37 |
+
"label2id": {
|
| 38 |
+
"LABEL_0": 0,
|
| 39 |
+
"LABEL_1": 1,
|
| 40 |
+
"LABEL_2": 2
|
| 41 |
+
},
|
| 42 |
+
"length_penalty": null,
|
| 43 |
+
"max_length": null,
|
| 44 |
+
"max_position_embeddings": 1024,
|
| 45 |
+
"min_length": null,
|
| 46 |
+
"model_type": "bart",
|
| 47 |
+
"no_repeat_ngram_size": null,
|
| 48 |
+
"normalize_before": false,
|
| 49 |
+
"num_beams": null,
|
| 50 |
+
"num_hidden_layers": 12,
|
| 51 |
+
"output_past": true,
|
| 52 |
+
"pad_token_id": 1,
|
| 53 |
+
"prefix": " ",
|
| 54 |
+
"scale_embedding": false,
|
| 55 |
+
"task_specific_params": {
|
| 56 |
+
"summarization": {
|
| 57 |
+
"early_stopping": true,
|
| 58 |
+
"length_penalty": 2.0,
|
| 59 |
+
"max_length": 142,
|
| 60 |
+
"min_length": 56,
|
| 61 |
+
"no_repeat_ngram_size": 3,
|
| 62 |
+
"num_beams": 4
|
| 63 |
+
}
|
| 64 |
+
},
|
| 65 |
+
"torch_dtype": "float32",
|
| 66 |
+
"transformers_version": "4.49.0",
|
| 67 |
+
"use_cache": true,
|
| 68 |
+
"vocab_size": 50264
|
| 69 |
+
}
|
summarizer_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.49.0"
|
| 16 |
+
}
|
summarizer_model/merges.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
summarizer_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 |
+
}
|
summarizer_model/tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
summarizer_model/tokenizer_config.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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": false,
|
| 47 |
+
"cls_token": "<s>",
|
| 48 |
+
"eos_token": "</s>",
|
| 49 |
+
"errors": "replace",
|
| 50 |
+
"extra_special_tokens": {},
|
| 51 |
+
"mask_token": "<mask>",
|
| 52 |
+
"model_max_length": 1000000000000000019884624838656,
|
| 53 |
+
"pad_token": "<pad>",
|
| 54 |
+
"sep_token": "</s>",
|
| 55 |
+
"tokenizer_class": "BartTokenizer",
|
| 56 |
+
"trim_offsets": true,
|
| 57 |
+
"unk_token": "<unk>"
|
| 58 |
+
}
|
summarizer_model/vocab.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tempCodeRunnerFile.python
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
# This prints the full path to where your model folder is located
|
| 4 |
+
print("Your model is here:")
|
| 5 |
+
print(os.path.abspath("./summarizer_model"))
|
| 6 |
+
|
| 7 |
+
# This checks if the files actually exist inside
|
| 8 |
+
if os.path.exists("./summarizer_model"):
|
| 9 |
+
print("\nFiles found:")
|
| 10 |
+
print(os.listdir("./summarizer_model"))
|
| 11 |
+
else:
|
| 12 |
+
print("\nFolder not found! Run the save script first.")
|