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| 10 |
+
---
|
| 11 |
+
<style>
|
| 12 |
+
.title-container {
|
| 13 |
+
display: flex;
|
| 14 |
+
flex-direction: column; /* Stack elements vertically */
|
| 15 |
+
justify-content: center;
|
| 16 |
+
align-items: center;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
.title {
|
| 20 |
+
font-size: 2em;
|
| 21 |
+
text-align: center;
|
| 22 |
+
color: #333;
|
| 23 |
+
font-family: 'Comic Sans MS', cursive; /* Use Comic Sans MS font */
|
| 24 |
+
text-transform: uppercase;
|
| 25 |
+
letter-spacing: 0.1em;
|
| 26 |
+
padding: 0.5em 0 0.2em;
|
| 27 |
+
background: transparent;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
.title span {
|
| 31 |
+
background: -webkit-linear-gradient(45deg, #6495ED, #4169E1); /* Blue gradient */
|
| 32 |
+
-webkit-background-clip: text;
|
| 33 |
+
-webkit-text-fill-color: transparent;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
.subheading {
|
| 37 |
+
font-size: 1.5em; /* Adjust the size as needed */
|
| 38 |
+
text-align: center;
|
| 39 |
+
color: #555; /* Adjust the color as needed */
|
| 40 |
+
font-family: 'Comic Sans MS', cursive; /* Use Comic Sans MS font */
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.authors {
|
| 44 |
+
font-size: 1em; /* Adjust the size as needed */
|
| 45 |
+
text-align: center;
|
| 46 |
+
color: #777; /* Adjust the color as needed */
|
| 47 |
+
font-family: 'Comic Sans MS', cursive; /* Use Comic Sans MS font */
|
| 48 |
+
padding-top: 1em;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
.affil {
|
| 52 |
+
font-size: 1em; /* Adjust the size as needed */
|
| 53 |
+
text-align: center;
|
| 54 |
+
color: #777; /* Adjust the color as needed */
|
| 55 |
+
font-family: 'Comic Sans MS', cursive; /* Use Comic Sans MS font */
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
</style>
|
| 59 |
+
|
| 60 |
+
<div class="title-container">
|
| 61 |
+
<div class="title">
|
| 62 |
+
Ta<span>il</span>s Tell Ta<span>le</span>s
|
| 63 |
+
</div>
|
| 64 |
+
<div class="subheading">
|
| 65 |
+
Chapter-Wide Manga Transcriptions With Character Names
|
| 66 |
+
</div>
|
| 67 |
+
<div class="authors">
|
| 68 |
+
Ragav Sachdeva, Gyungin Shin and Andrew Zisserman
|
| 69 |
+
</div>
|
| 70 |
+
<div class="affil">
|
| 71 |
+
University of Oxford
|
| 72 |
+
</div>
|
| 73 |
+
<div style="display: flex;">
|
| 74 |
+
<a href="https://arxiv.org/abs/2408.00298"><img alt="Static Badge" src="https://img.shields.io/badge/arXiv-2408.00298-blue"></a>
|
| 75 |
+
 
|
| 76 |
+
<img alt="Dynamic JSON Badge" src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fhuggingface.co%2Fapi%2Fmodels%2Fragavsachdeva%2Fmagiv2%3Fexpand%255B%255D%3Ddownloads%26expand%255B%255D%3DdownloadsAllTime&query=%24.downloadsAllTime&label=%F0%9F%A4%97%20Downloads">
|
| 77 |
+
</div>
|
| 78 |
+
</div>
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+

|
| 82 |
+
|
| 83 |
+
# Usage
|
| 84 |
+
```python
|
| 85 |
+
from PIL import Image
|
| 86 |
+
import numpy as np
|
| 87 |
+
from transformers import AutoModel
|
| 88 |
+
import torch
|
| 89 |
+
|
| 90 |
+
model = AutoModel.from_pretrained("ragavsachdeva/magiv2", trust_remote_code=True).cuda().eval()
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def read_image(path_to_image):
|
| 94 |
+
with open(path_to_image, "rb") as file:
|
| 95 |
+
image = Image.open(file).convert("L").convert("RGB")
|
| 96 |
+
image = np.array(image)
|
| 97 |
+
return image
|
| 98 |
+
|
| 99 |
+
chapter_pages = ["page1.png", "page2.png", "page3.png" ...]
|
| 100 |
+
character_bank = {
|
| 101 |
+
"images": ["char1.png", "char2.png", "char3.png", "char4.png" ...],
|
| 102 |
+
"names": ["Luffy", "Sanji", "Zoro", "Ussop" ...]
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
chapter_pages = [read_image(x) for x in chapter_pages]
|
| 106 |
+
character_bank["images"] = [read_image(x) for x in character_bank["images"]]
|
| 107 |
+
|
| 108 |
+
with torch.no_grad():
|
| 109 |
+
per_page_results = model.do_chapter_wide_prediction(chapter_pages, character_bank, use_tqdm=True, do_ocr=True)
|
| 110 |
+
|
| 111 |
+
transcript = []
|
| 112 |
+
for i, (image, page_result) in enumerate(zip(chapter_pages, per_page_results)):
|
| 113 |
+
model.visualise_single_image_prediction(image, page_result, f"page_{i}.png")
|
| 114 |
+
speaker_name = {
|
| 115 |
+
text_idx: page_result["character_names"][char_idx] for text_idx, char_idx in page_result["text_character_associations"]
|
| 116 |
+
}
|
| 117 |
+
for j in range(len(page_result["ocr"])):
|
| 118 |
+
if not page_result["is_essential_text"][j]:
|
| 119 |
+
continue
|
| 120 |
+
name = speaker_name.get(j, "unsure")
|
| 121 |
+
transcript.append(f"<{name}>: {page_result['ocr'][j]}")
|
| 122 |
+
with open(f"transcript.txt", "w") as fh:
|
| 123 |
+
for line in transcript:
|
| 124 |
+
fh.write(line + "\n")
|
| 125 |
+
```
|
| 126 |
+
|
| 127 |
+
# License and Citation
|
| 128 |
+
The provided model and datasets are available for unrestricted use in personal, research, non-commercial, and not-for-profit endeavors. For any other usage scenarios, kindly contact me via email, providing a detailed description of your requirements, to establish a tailored licensing arrangement.
|
| 129 |
+
My contact information can be found on my website: ragavsachdeva [dot] github [dot] io
|
| 130 |
+
|
| 131 |
+
```
|
| 132 |
+
@misc{magiv2,
|
| 133 |
+
title={Tails Tell Tales: Chapter-Wide Manga Transcriptions with Character Names},
|
| 134 |
+
author={Ragav Sachdeva and Gyungin Shin and Andrew Zisserman},
|
| 135 |
+
year={2024},
|
| 136 |
+
eprint={2408.00298},
|
| 137 |
+
archivePrefix={arXiv},
|
| 138 |
+
primaryClass={cs.CV},
|
| 139 |
+
url={https://arxiv.org/abs/2408.00298},
|
| 140 |
+
}
|
| 141 |
+
```
|