peyro-summarizer 0.1.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ from importlib.metadata import version
2
+
3
+ from .run import summarizer
4
+
5
+ __version__ = version("peyro_summarizer")
6
+ __all__ = ["summarizer", "__version__"]
@@ -0,0 +1,25 @@
1
+ from .config import FOLDER, CHUNK
2
+ import fitz, json, os
3
+ from unstructured.partition.text import partition_text
4
+ from unstructured.chunking.title import chunk_by_title
5
+
6
+ async def chunk(path):
7
+ os.makedirs(FOLDER, exist_ok=True)
8
+ doc = fitz.open(path)
9
+ for page in doc:
10
+ text = page.get_text()
11
+ elements = partition_text(text)
12
+ chunks = chunk_by_title(elements, max_characters=2000)
13
+ with open(f"{FOLDER}/{CHUNK}.jsonl", "a", encoding="utf-8") as f:
14
+ current_title = "Untitled"
15
+ current_text =""
16
+ for chunk in chunks:
17
+ if chunk.category == "Title":
18
+ if current_text.strip():
19
+ f.write(json.dumps({"title": current_title, "text": current_text.strip()}, ensure_ascii=False) + "\n")
20
+ current_title = chunk.text.strip()
21
+ current_text =""
22
+ else:
23
+ current_text += " " + chunk.text.strip()
24
+ if current_text.strip():
25
+ f.write(json.dumps({"title": current_title, "text": current_text.strip()}, ensure_ascii=False) + "\n")
@@ -0,0 +1,3 @@
1
+ FOLDER = "peyro"
2
+ CHUNK = "chunk"
3
+ SUMMARY = "summary"
@@ -0,0 +1,25 @@
1
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
2
+ from .config import FOLDER, SUMMARY, CHUNK
3
+ import json, os, torch
4
+
5
+ MODEL_NAME = "google/flan-t5-small"
6
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
7
+ model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME)
8
+ model.eval()
9
+
10
+ async def summarize():
11
+ chunk_path = f"{FOLDER}/{CHUNK}.jsonl"
12
+ summary_path = f"{FOLDER}/{SUMMARY}.jsonl"
13
+ blobs = []
14
+ with open(chunk_path, "r") as f:
15
+ for line in f:
16
+ blobs.append(json.loads(line))
17
+ for b in blobs:
18
+ inputs = tokenizer(b["text"], return_tensors="pt", truncation=True, max_length=512)
19
+ with torch.no_grad():
20
+ output_ids = model.generate(**inputs, max_new_tokens=100)
21
+
22
+ outputs = tokenizer.decode(output_ids[0], skip_special_tokens=True)
23
+ body = tokenizer.decode(outputs[0], skip_special_tokens=True)
24
+ with open(summary_path, "a", encoding="utf-8") as f:
25
+ f.write(json.dumps({"title": b["title"], "body": body}, ensure_ascii=False) +"\n")
@@ -0,0 +1,6 @@
1
+ from huggingface_hub import snapshot_download
2
+
3
+ MODEL_NAME = "google/flan-t5-small"
4
+
5
+ async def get_model():
6
+ snapshot_download(MODEL_NAME)
@@ -0,0 +1,23 @@
1
+ import fitz, os
2
+ from .config import FOLDER
3
+
4
+ class Create_PDF:
5
+ def __init__():
6
+ self.doc = fitz.open()
7
+ self.page = self.doc.new_page(width=595, height=842)
8
+ self.y = 80
9
+
10
+ def add_section(self, title, body):
11
+ self.page.insert_text((70, self.y), title, fontsize=20, color=(0,0,0))
12
+ self.y += 30
13
+ self.page.insert_text((70, self.y), body, fontsize=12)
14
+ self.y += 60
15
+
16
+ def save(self, filename):
17
+ os.makedirs(FOLDER, exist_ok=True)
18
+ storage_path = f"{FOLDER}/{filename}.pdf"
19
+ self.doc.save(storage_path)
20
+ self.doc.close()
21
+ return storage_path
22
+
23
+
@@ -0,0 +1,42 @@
1
+ from .pdf_export import Create_PDF
2
+ from .chunk import chunk
3
+ from .config import FOLDER, SUMMARY
4
+ from .inference import summarize
5
+ from .models.model_manager import get_model
6
+ import json, os
7
+
8
+ async def summarizer(path):
9
+ try:
10
+ os.makedirs(FOLDER, exist_ok=True)
11
+ filename = os.path.basename(path)
12
+ p = f"{FOLDER}/{SUMMARY}.jsonl"
13
+ await get_model()
14
+ yield{"message":"Loaded Model", "path": None, "success": None}
15
+ await chunk(path)
16
+ await summarize()
17
+ yield{"message":"Finished Summary", "path": None, "success": None}
18
+
19
+ blob = []
20
+ with open(p, "r") as f:
21
+ for line in f:
22
+ blob.append(json.loads(line))
23
+
24
+ pdf = Create_PDF()
25
+ for d in blob:
26
+ pdf.add_section(title=d["title"], body=d["body"])
27
+ yield{"message":"Creating pdf", "path": None, "success": None}
28
+ output_path = pdf.save(filename)
29
+ yield{"success": True,
30
+ "path": output_path, "message": "successful"}
31
+
32
+ except FileNotFoundError:
33
+ yield{"success": False, "path": None,
34
+ "message": "File not found"}
35
+
36
+ except Exception as e:
37
+ yield{"success": False, "path": None,
38
+ "message": f"An error occurred while summarizing:{e}"}
39
+
40
+ finally:
41
+ os.remove(p)
42
+ os.remove(f"{FOLDER}/{CHUNK}.jsonl")
@@ -0,0 +1,16 @@
1
+ Metadata-Version: 2.4
2
+ Name: peyro_summarizer
3
+ Version: 0.1.2
4
+ Summary: An AI powered document summarization
5
+ Author-email: Jarvis <jarviskrost2000@gmail.com>
6
+ Requires-Python: >=3.9
7
+ License-File: LICENSE
8
+ Requires-Dist: PyMuPDF
9
+ Requires-Dist: unstructured
10
+ Requires-Dist: transformers
11
+ Requires-Dist: sentencepiece
12
+ Requires-Dist: torch
13
+ Provides-Extra: dev
14
+ Requires-Dist: pytest; extra == "dev"
15
+ Requires-Dist: ruff; extra == "dev"
16
+ Dynamic: license-file
@@ -0,0 +1,13 @@
1
+ peyro_summarizer/__init__.py,sha256=k60td9CJvSXByW1A2FK6NTA6Jexy8SOu2afvWHZ6-_Y,150
2
+ peyro_summarizer/chunk.py,sha256=PMOnQZ9YozZEfEpzjz6yG3xBuNm5bzCFTfvTG_y049w,1133
3
+ peyro_summarizer/config.py,sha256=h9DCy2tdwNrfZ5NH6QoFoS3N-PZQSi_iuXtEA4XRPvY,52
4
+ peyro_summarizer/inference.py,sha256=g4UBSXWyoKkMGSV1-tNS0C70AWgt5CRO9qIPtmpTd64,1036
5
+ peyro_summarizer/pdf_export.py,sha256=y2HlLo7iVULwR2g2Vzw61a3cegCjK7LCya7DWUOhslE,662
6
+ peyro_summarizer/run.py,sha256=1ETF1_1jJtQMCyumgu0vsyUUa4yVZF8G2qAZbFgfLCo,1422
7
+ peyro_summarizer/models/model_manager.py,sha256=84sodNkG3bV6RdrAUxQHrHrPfBmu3NIR4t8ze5aDdJI,141
8
+ peyro_summarizer-0.1.2.dist-info/licenses/LICENSE,sha256=KorqZV8EnFRpha-f6_0f8GcaKhn0N6r6l_7AfoMe714,1063
9
+ peyro_summarizer-0.1.2.dist-info/METADATA,sha256=qNM5KDPbVCRYSMUEDxOP7kICpuHQEGBURshNyMSwkP4,445
10
+ peyro_summarizer-0.1.2.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
11
+ peyro_summarizer-0.1.2.dist-info/entry_points.txt,sha256=TJxi1I5PYNRxoyiaipGn2da3rT0uzI2NNBPo_sWe1tk,63
12
+ peyro_summarizer-0.1.2.dist-info/top_level.txt,sha256=1WnGM8Yf636OYUp5EnOUGc2gNrVxrQb1m1CQraCxlgw,17
13
+ peyro_summarizer-0.1.2.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [host_app.plugins]
2
+ my_plugin = peyro_summarizer.run:summarizer
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jarvis
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ peyro_summarizer