remiai3 commited on
Commit
3e56582
·
verified ·
1 Parent(s): c7ad910

Upload 4 files

Browse files
Files changed (4) hide show
  1. README.md +22 -3
  2. inference.py +26 -0
  3. main.py +20 -0
  4. requirements.txt +9 -0
README.md CHANGED
@@ -1,3 +1,22 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Text Summarization (CPU/GPU)
2
+
3
+ - **Model:** `sshleifer/distilbart-cnn-12-6` (Apache-2.0)
4
+ - **Task:** Abstractive summarization.
5
+ - **Note:** Here we just provide the resources for to run this models in the laptops we didn't develop this entire models we just use the open source models for the experiment this model is developed by sshleifer
6
+
7
+ ## Quick start (any project)
8
+
9
+ ```bash
10
+ # 1) Create env
11
+ python -m venv venv && source .venv/bin/activate # Windows: ./venv/Scripts/activate
12
+
13
+ # 2) Install deps
14
+ pip install -r requirements.txt
15
+
16
+ # 3) Run
17
+ python main.py --help
18
+ ```
19
+
20
+ > Tip: If you have a GPU + CUDA, PyTorch will auto-use it. If not, everything runs on CPU (slower but works).
21
+
22
+ ---
inference.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import pipeline
3
+
4
+ MODEL_NAME = "sshleifer/distilbart-cnn-12-6"
5
+ device = 0 if torch.cuda.is_available() else -1
6
+
7
+ summarizer = pipeline(
8
+ "summarization",
9
+ model=MODEL_NAME,
10
+ device=device
11
+ )
12
+
13
+ texts = [
14
+ (
15
+ "Artificial intelligence is transforming education by enabling personalized learning. "
16
+ "Teachers can use AI-driven tools to understand student progress and tailor activities."
17
+ ),
18
+ (
19
+ "The James Webb Space Telescope has captured stunning new images of distant galaxies, "
20
+ "providing insights into the early universe and the formation of cosmic structures."
21
+ )
22
+ ]
23
+
24
+ for text in texts:
25
+ summary = summarizer(text, max_length=120, min_length=40, do_sample=False)
26
+ print(f"Original: {text}\nSummary: {summary[0]['summary_text']}\n")
main.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse, torch
2
+ from transformers import pipeline
3
+
4
+ def main():
5
+ parser = argparse.ArgumentParser()
6
+ parser.add_argument("--text", type=str, default=(
7
+ "Artificial intelligence is transforming education by enabling personalized learning. "
8
+ "Teachers can use AI-driven tools to understand student progress and tailor activities."
9
+ ))
10
+ parser.add_argument("--max_length", type=int, default=120)
11
+ parser.add_argument("--min_length", type=int, default=40)
12
+ args = parser.parse_args()
13
+
14
+ device = 0 if torch.cuda.is_available() else -1
15
+ summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6", device=device)
16
+ out = summarizer(args.text, max_length=args.max_length, min_length=args.min_length, do_sample=False)
17
+ print(out[0]["summary_text"])
18
+
19
+ if __name__ == "__main__":
20
+ main()
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ torch==2.1.0
2
+ torchvision==0.16.0
3
+ torchaudio==2.1.0
4
+ transformers==4.38.2
5
+ datasets==2.18.0
6
+ Pillow==10.2.0
7
+ numpy==1.26.4
8
+ tqdm==4.66.2
9
+ sentencepiece==0.1.99