MattyMroz commited on
Commit
4ef9317
1 Parent(s): 93dc455

Upload 4 files

Browse files
Files changed (4) hide show
  1. 1.jpg +3 -0
  2. 1.png +3 -0
  3. manga-whisperer.py +35 -0
  4. requirements.txt +8 -0
1.jpg ADDED

Git LFS Details

  • SHA256: bd32023d0c8cd7fa9364a698f8c0628c16d9b044dfbdebaee4d35d5330a01a34
  • Pointer size: 131 Bytes
  • Size of remote file: 426 kB
1.png ADDED

Git LFS Details

  • SHA256: a34543bb308daa3fe76880d47d2d803b09734cd21c30af78ca36975446a25dcb
  • Pointer size: 131 Bytes
  • Size of remote file: 393 kB
manga-whisperer.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModel
2
+ import numpy as np
3
+ from PIL import Image
4
+ import torch
5
+ import os
6
+
7
+ images = [
8
+ "1.png",
9
+ "1.jpg",
10
+ ]
11
+
12
+
13
+ def read_image_as_np_array(image_path):
14
+ with open(image_path, "rb") as file:
15
+ image = Image.open(file).convert("L").convert("RGB")
16
+ image = np.array(image)
17
+ return image
18
+
19
+
20
+ images = [read_image_as_np_array(image) for image in images]
21
+
22
+ model = AutoModel.from_pretrained(
23
+ "ragavsachdeva/magi", trust_remote_code=True).cuda()
24
+ # model = AutoModel.from_pretrained(
25
+ # "./magi", trust_remote_code=True).cuda()
26
+ with torch.no_grad():
27
+ results = model.predict_detections_and_associations(images)
28
+ text_bboxes_for_all_images = [x["texts"] for x in results]
29
+ ocr_results = model.predict_ocr(images, text_bboxes_for_all_images)
30
+
31
+ for i in range(len(images)):
32
+ model.visualise_single_image_prediction(
33
+ images[i], results[i], filename=f"image_{i}.png")
34
+ model.generate_transcript_for_single_image(
35
+ results[i], ocr_results[i], filename=f"transcript_{i}.txt")
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ transformers
2
+ einops
3
+ --extra-index-url https://download.pytorch.org/whl/cu113
4
+ torch
5
+ shapely
6
+ timm
7
+ scipy
8
+ tokenizers