lityops commited on
Commit
2eab398
·
verified ·
1 Parent(s): 42021b5

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +26 -14
  2. app.py +90 -104
  3. requirements.txt +3 -3
README.md CHANGED
@@ -1,14 +1,26 @@
1
- ---
2
- title: Style Summarizer
3
- emoji: 🌖
4
- colorFrom: red
5
- colorTo: purple
6
- sdk: gradio
7
- sdk_version: 6.2.0
8
- app_file: app.py
9
- pinned: false
10
- license: mit
11
- short_description: Generate summaries in different styles
12
- ---
13
-
14
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Abstractive Style Summarizer
3
+ emoji: ✍️
4
+ colorFrom: blue
5
+ colorTo: indigo
6
+ sdk: gradio
7
+ sdk_version: 6.2.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: mit
11
+ short_description: Generate summaries in different styles
12
+ ---
13
+
14
+ # Abstractive Style Summarizer
15
+
16
+ A multi-style abstractive text summarization tool powered by the `lityops/Abstractive-Style-Summarizer` model (fine-tuned Flan-T5 Base).
17
+
18
+ ## Features
19
+
20
+ - **Harsh**: Very concise summaries, effectively extracting the core gist.
21
+ - **Balanced**: A middle ground, balancing detail and brevity.
22
+ - **Detailed**: Longer summaries preserving more context and information.
23
+
24
+ ## Usage
25
+
26
+ Enter your text in the input box, select your desired style, and click "Process Summary".
app.py CHANGED
@@ -1,104 +1,90 @@
1
- import gradio as gr
2
- from transformers import pipeline
3
-
4
- MODEL_ID = 'lityops/Style-Summarizer'
5
-
6
- summarizer = pipeline("summarization", model=MODEL_ID)
7
-
8
- def generate_summary(text, style):
9
- if not text or len(text.strip()) < 50:
10
- return "Input must at least be 50 words long"
11
-
12
- input_text = f"summarize {style}: {text}"
13
- input_words = len(text.split())
14
-
15
- if style == 'harsh':
16
- max_len = int(input_words * 0.35)
17
- min_len = 5
18
- rep_penalty = 2.5
19
- length_penalty = 1.5
20
- beam_size = 4
21
- max_cap = 120
22
- elif style == 'balanced':
23
- max_len = int(input_words * 0.50)
24
- min_len = 20
25
- rep_penalty = 1.5
26
- length_penalty = 1.2
27
- beam_size = 4
28
- max_cap = 180
29
- else:
30
- max_len = int(input_words * 0.70)
31
- min_len = 50
32
- rep_penalty = 1.2
33
- length_penalty = 0.8
34
- beam_size = 4
35
- max_cap = 256
36
-
37
- max_len = min(max_len, max_cap)
38
-
39
- output = summarizer(
40
- input_text,
41
- max_length=max_len,
42
- min_length=min_len,
43
- num_beams=beam_size,
44
- length_penalty=length_penalty,
45
- repetition_penalty=rep_penalty,
46
- no_repeat_ngram_size=3,
47
- early_stopping=True
48
- )
49
- return output[0]["summary_text"]
50
-
51
- custom_css = """
52
- #header {text-align: center; margin-bottom: 25px;}
53
- .gradio-container {max-width: 95% !important;}
54
- footer {display: none !important;}
55
- """
56
-
57
- with gr.Blocks() as demo:
58
- with gr.Column(elem_id="header"):
59
- gr.Markdown("# Style Summarizer")
60
- gr.Markdown("Fine-tuned Flan-T5 model for multi-style document summarization.")
61
-
62
- with gr.Row():
63
- with gr.Column(scale=1):
64
- input_box = gr.Textbox(
65
- label="Input Text",
66
- placeholder="Enter text to be summarized...",
67
- lines=15
68
- )
69
- style_radio = gr.Radio(
70
- choices=["harsh", "standard", "detailed"],
71
- label="Summary Type",
72
- value="standard"
73
- )
74
- with gr.Row():
75
- clear_btn = gr.Button("Clear Input")
76
- submit_btn = gr.Button("Process Summary", variant="primary")
77
-
78
- with gr.Column(scale=1):
79
- output_box = gr.Textbox(
80
- label="Output Summary",
81
- lines=18,
82
- interactive=False
83
- )
84
- copy_btn = gr.Button("Copy to Clipboard")
85
-
86
- submit_btn.click(
87
- fn=generate_summary,
88
- inputs=[input_box, style_radio],
89
- outputs=output_box
90
- )
91
-
92
- clear_btn.click(
93
- fn=lambda: "",
94
- inputs=None,
95
- outputs=input_box
96
- )
97
-
98
- copy_btn.click(
99
- fn=None,
100
- inputs=[output_box],
101
- js="(v) => { navigator.clipboard.writeText(v); }"
102
- )
103
-
104
- demo.launch(css=custom_css, theme=gr.themes.Base())
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ MODEL_ID = 'lityops/Abstractive-Style-Summarizer'
5
+
6
+ summarizer = pipeline("summarization", model=MODEL_ID)
7
+
8
+ def generate_summary(text, style):
9
+ if not text or len(text.strip()) < 50:
10
+ return "Input must at least be 50 words long"
11
+
12
+ input_text = f"Summarize {style}: {text}"
13
+ input_words = len(text.split())
14
+
15
+ if style == 'Harsh':
16
+ max_len = int(input_words * 0.35)
17
+ min_len = 5
18
+ rep_penalty = 2.5
19
+ length_penalty = 1.5
20
+ beam_size = 4
21
+ max_cap = 120
22
+ elif style == 'Balanced':
23
+ max_len = int(input_words * 0.50)
24
+ min_len = 20
25
+ rep_penalty = 1.5
26
+ length_penalty = 1.2
27
+ beam_size = 4
28
+ max_cap = 180
29
+ else:
30
+ max_len = int(input_words * 0.70)
31
+ min_len = 50
32
+ rep_penalty = 1.2
33
+ length_penalty = 0.8
34
+ beam_size = 4
35
+ max_cap = 256
36
+
37
+ max_len = min(max_len, max_cap)
38
+
39
+ output = summarizer(
40
+ input_text,
41
+ max_length=max_len,
42
+ min_length=min_len,
43
+ num_beams=beam_size,
44
+ length_penalty=length_penalty,
45
+ repetition_penalty=rep_penalty,
46
+ no_repeat_ngram_size=3,
47
+ early_stopping=True
48
+ )
49
+ return output[0]["summary_text"]
50
+
51
+ custom_css = """
52
+ #header {text-align: center; margin-bottom: 25px;}
53
+ .gradio-container {max-width: 1000px !important;}
54
+ footer {display: none !important;}
55
+ """
56
+
57
+ with gr.Blocks(css=custom_css, theme=gr.themes.Base()) as demo:
58
+ with gr.Column(elem_id="header"):
59
+ gr.Markdown("# Style Summarizer")
60
+ gr.Markdown("Fine-tuned Flan-T5 model for multi-style document summarization.")
61
+
62
+ with gr.Row():
63
+ with gr.Column(scale=1):
64
+ input_box = gr.Textbox(
65
+ label="Input Text",
66
+ placeholder="Enter text to be summarized...",
67
+ lines=12
68
+ )
69
+ style_radio = gr.Radio(
70
+ choices=["Harsh", "Balanced", "Detailed"],
71
+ label="Summary Type",
72
+ value="Balanced"
73
+ )
74
+ submit_btn = gr.Button("Process Summary", variant="primary")
75
+
76
+ with gr.Column(scale=1):
77
+ output_box = gr.Textbox(
78
+ label="Output Summary",
79
+ lines=15,
80
+ interactive=False,
81
+ show_copy_button=True
82
+ )
83
+
84
+ submit_btn.click(
85
+ fn=generate_summary,
86
+ inputs=[input_box, style_radio],
87
+ outputs=output_box
88
+ )
89
+
90
+ demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
requirements.txt CHANGED
@@ -1,3 +1,3 @@
1
- gradio
2
- torch
3
- transformers
 
1
+ gradio
2
+ torch>=2.5.1
3
+ transformers>=4.36.0