abersbail commited on
Commit
d4b7b19
Β·
verified Β·
1 Parent(s): 0b41e68

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. README.md +13 -5
  2. __pycache__/app.cpython-313.pyc +0 -0
  3. app.py +95 -28
  4. requirements.txt +3 -5
README.md CHANGED
@@ -1,13 +1,21 @@
1
  ---
2
- title: Text Summarizer CPU
 
3
  colorFrom: blue
4
- colorTo: green
5
  sdk: gradio
 
6
  app_file: app.py
7
  pinned: false
8
- license: apache-2.0
9
  ---
10
 
11
- # Text Summarizer CPU
12
 
13
- Free CPU text summarizer using `google/flan-t5-small`.
 
 
 
 
 
 
 
1
  ---
2
+ title: AI Smart Text Summarizer
3
+ emoji: πŸ“
4
  colorFrom: blue
5
+ colorTo: indigo
6
  sdk: gradio
7
+ sdk_version: 4.44.0
8
  app_file: app.py
9
  pinned: false
10
+ license: mit
11
  ---
12
 
13
+ # Smart AI Text Summarizer & Key Insights
14
 
15
+ An intelligent NLP application built with Gradio and Hugging Face Transformers (`sshleifer/distilbart-cnn-12-6`) to summarize long documents and extract key insights instantly.
16
+
17
+ ## Features
18
+ - Abstractive AI summarization
19
+ - Adjustable length controls
20
+ - Automated key highlights extraction
21
+ - Real-time word count & reading time reduction analytics
__pycache__/app.cpython-313.pyc ADDED
Binary file (7.06 kB). View file
 
app.py CHANGED
@@ -1,44 +1,111 @@
1
  import gradio as gr
 
 
2
 
3
- from summary_tool.service import SummaryService
 
 
 
 
 
4
 
 
 
 
 
 
 
 
 
5
 
6
- service = SummaryService()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
- def summarize_text(text, style, max_words):
10
- return service.summarize(text, style, int(max_words))
11
 
 
12
 
13
- with gr.Blocks(
14
- title="Text Summarizer CPU",
15
- theme=gr.themes.Soft(primary_hue="blue", secondary_hue="green"),
16
- ) as demo:
17
  gr.Markdown(
18
  """
19
- # Text Summarizer CPU
20
- Paste long text and generate a short AI summary on free CPU.
21
  """
22
  )
23
-
24
- text_input = gr.Textbox(label="Input Text", lines=12, placeholder="Paste article, notes, or long text here")
25
- style_input = gr.Dropdown(
26
- choices=["Short", "Balanced", "Detailed", "Bullet Points"],
27
- value="Balanced",
28
- label="Summary Style",
29
- )
30
- max_words_input = gr.Slider(40, 240, value=120, step=10, label="Max Words")
31
- run_button = gr.Button("Summarize", variant="primary")
32
-
33
- summary_output = gr.Textbox(label="Summary", lines=8)
34
- status_output = gr.Textbox(label="Status", lines=2)
35
-
36
- run_button.click(
37
- fn=summarize_text,
38
- inputs=[text_input, style_input, max_words_input],
39
- outputs=[summary_output, status_output],
 
 
 
 
 
 
 
 
 
 
 
 
40
  )
41
 
42
-
43
  if __name__ == "__main__":
44
  demo.launch()
 
1
  import gradio as gr
2
+ import re
3
+ from transformers import pipeline
4
 
5
+ # Load lightweight, fast summarization pipeline
6
+ try:
7
+ summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
8
+ except Exception as e:
9
+ summarizer = None
10
+ print(f"Pipeline loading error: {e}")
11
 
12
+ def extract_key_points(text, num_points=3):
13
+ """Extract key sentence points based on sentence length & structure."""
14
+ sentences = [s.strip() for s in re.split(r'(?<=[.!?]) +', text) if len(s.strip()) > 10]
15
+ if not sentences:
16
+ return "β€’ No key sentences identified."
17
+ # Sort sentences by length/informativeness as simple heuristic
18
+ key_sentences = sorted(sentences, key=lambda s: len(s), reverse=True)[:num_points]
19
+ return "\n".join([f"β€’ {s}" for s in key_sentences])
20
 
21
+ def analyze_and_summarize(text, max_len, min_len):
22
+ if not text or len(text.strip()) < 30:
23
+ return (
24
+ "⚠️ Please enter a longer text (at least 30 characters) to summarize.",
25
+ "N/A",
26
+ "N/A",
27
+ "N/A"
28
+ )
29
+
30
+ words_input = len(text.split())
31
+
32
+ try:
33
+ if summarizer:
34
+ summary_res = summarizer(
35
+ text,
36
+ max_length=int(max_len),
37
+ min_length=int(min_len),
38
+ do_sample=False
39
+ )
40
+ summary_text = summary_res[0]['summary_text']
41
+ else:
42
+ # Fallback heuristic summary if pipeline fails to load
43
+ sentences = [s.strip() for s in re.split(r'(?<=[.!?]) +', text) if len(s.strip()) > 5]
44
+ summary_text = " ".join(sentences[:max(1, len(sentences)//2)])
45
+ except Exception as err:
46
+ # Fallback if text is shorter than min_length or another edge case occurs
47
+ sentences = [s.strip() for s in re.split(r'(?<=[.!?]) +', text) if len(s.strip()) > 5]
48
+ summary_text = " ".join(sentences[:2]) if sentences else text
49
 
50
+ words_summary = len(summary_text.split())
51
+ reduction = max(0, round((1 - (words_summary / words_input)) * 100, 1)) if words_input > 0 else 0
52
+ read_time_saved = max(0, round((words_input - words_summary) / 200, 1))
53
+
54
+ key_bullets = extract_key_points(text)
55
+
56
+ stats_md = f"""
57
+ ### πŸ“Š Summary Analytics
58
+ - **Original Word Count**: `{words_input}` words
59
+ - **Summary Word Count**: `{words_summary}` words
60
+ - **Text Reduction**: `{reduction}%` smaller
61
+ - **Est. Reading Time Saved**: `{read_time_saved} minutes`
62
+ """
63
+
64
+ return summary_text, key_bullets, stats_md
65
 
66
+ example_1 = """Artificial intelligence (AI) is transforming industries worldwide, from healthcare and finance to education and transport. Deep learning models, powered by neural networks with millions or billions of parameters, have achieved unprecedented capabilities in natural language understanding, computer vision, and autonomous decision making. As these technologies evolve, researchers emphasize the importance of AI safety, ethics, and transparency to ensure AI systems remain aligned with human values and societal benefit."""
 
67
 
68
+ example_2 = """Machine learning algorithms build a mathematical model based on sample data, known as training data, to make predictions or decisions without being explicitly programmed to do so. Supervised learning algorithms build a mathematical model of a set of data that contains both the inputs and the desired outputs. Unsupervised learning algorithms take a set of data that contains only inputs, and find structure in the data, like grouping or clustering of data points."""
69
 
70
+ demo = gr.Blocks(theme=gr.themes.Soft())
71
+
72
+ with demo:
 
73
  gr.Markdown(
74
  """
75
+ # πŸ“ Smart AI Text Summarizer & Insight Extractor
76
+ *Transform lengthy articles, essays, and documents into concise, highly readable summaries powered by Deep Learning.*
77
  """
78
  )
79
+
80
+ with gr.Row():
81
+ with gr.Column(scale=1):
82
+ input_text = gr.Textbox(
83
+ label="Input Document / Article Text",
84
+ placeholder="Paste your paragraph or article here...",
85
+ lines=10
86
+ )
87
+
88
+ with gr.Row():
89
+ max_slider = gr.Slider(minimum=30, maximum=300, value=130, step=10, label="Max Summary Length")
90
+ min_slider = gr.Slider(minimum=10, maximum=100, value=30, step=5, label="Min Summary Length")
91
+
92
+ submit_btn = gr.Button("⚑ Summarize & Extract Insights", variant="primary")
93
+
94
+ gr.Examples(
95
+ examples=[[example_1, 130, 30], [example_2, 100, 25]],
96
+ inputs=[input_text, max_slider, min_slider]
97
+ )
98
+
99
+ with gr.Column(scale=1):
100
+ output_summary = gr.Textbox(label="✨ AI Abstractive Summary", lines=5)
101
+ output_bullets = gr.Textbox(label="πŸ“Œ Key Highlight Points", lines=4)
102
+ output_stats = gr.Markdown(label="Analytics")
103
+
104
+ submit_btn.click(
105
+ fn=analyze_and_summarize,
106
+ inputs=[input_text, max_slider, min_slider],
107
+ outputs=[output_summary, output_bullets, output_stats]
108
  )
109
 
 
110
  if __name__ == "__main__":
111
  demo.launch()
requirements.txt CHANGED
@@ -1,5 +1,3 @@
1
- gradio>=5.23.0
2
- huggingface_hub>=0.34.0,<1.0
3
- safetensors>=0.5.3
4
- torch>=2.3.0
5
- transformers>=4.49.0
 
1
+ transformers>=4.30.0
2
+ torch>=2.0.0
3
+ gradio>=4.0.0