-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8a33772
Showing
42 changed files
with
5,539 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.venv | ||
__pycache__ | ||
dist | ||
*.spec | ||
build | ||
browser_context |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Transmanga | ||
|
||
Translate manga using Microsoft Copilot (Bing Chat) or Google Translate. | ||
|
||
| Original | English | | ||
| ------------------------------ | ----------------------------- | | ||
| ![](docs/example/original.jpg) | ![](docs/example/english.png) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import subprocess | ||
import pathlib | ||
|
||
|
||
def build(): | ||
client_path = pathlib.Path(__file__).parent / "transmanga" / "client" | ||
subprocess.run("npm install", shell=True, check=True, cwd=client_path) | ||
subprocess.run("npm run build", shell=True, check=True, cwd=client_path) | ||
|
||
|
||
if __name__ == "__main__": | ||
build() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import transmanga.__main__ | ||
|
||
transmanga.__main__.main() |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
[tool.poetry] | ||
name = "transmanga" | ||
version = "0.1.0" | ||
description = "Translate manga" | ||
authors = ["tuhm1 <hmtu117@gmail.com>"] | ||
readme = "README.md" | ||
build = "build.py" | ||
|
||
[tool.poetry.dependencies] | ||
python = ">=3.11,<3.13" | ||
manga-ocr = "^0.1.11" | ||
translators = "^5.8.9" | ||
mediapipe = "^0.10.9" | ||
pywebview = "^4.4.1" | ||
playwright = "^1.41.2" | ||
|
||
[tool.poetry.group.dev.dependencies] | ||
pyinstaller = "^6.3.0" | ||
poethepoet = "^0.24.4" | ||
|
||
[build-system] | ||
requires = ["poetry-core"] | ||
build-backend = "poetry.core.masonry.api" | ||
|
||
[tool.poe.tasks] | ||
build = '''pyinstaller | ||
--add-data transmanga/client/dist:transmanga/client/dist | ||
--add-data transmanga/detector.tflite:transmanga | ||
--collect-data mediapipe | ||
--hidden-import unidic_lite | ||
--collect-data unidic_lite | ||
--collect-binaries unidic_lite | ||
--collect-data manga_ocr | ||
--windowed | ||
--name transmanga | ||
--icon translate.ico | ||
--clean | ||
main.py''' |
Empty file.
Binary file not shown.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import mediapipe as mp | ||
import cv2 | ||
import numpy as np | ||
from manga_ocr import MangaOcr | ||
from PIL import Image | ||
import io | ||
import base64 | ||
import translators | ||
import webview | ||
import mimetypes as mime | ||
import json | ||
import pathlib | ||
from transmanga import copilot | ||
from concurrent import futures | ||
import os | ||
|
||
|
||
def main(): | ||
detector = mp.tasks.vision.ObjectDetector.create_from_options( | ||
mp.tasks.vision.ObjectDetectorOptions( | ||
base_options=mp.tasks.BaseOptions( | ||
model_asset_path=pathlib.Path(__file__, "../detector.tflite"), | ||
), | ||
score_threshold=0.5, | ||
running_mode=mp.tasks.vision.RunningMode.IMAGE, | ||
) | ||
) | ||
|
||
mocr_executor = futures.ThreadPoolExecutor() | ||
future_mocr = mocr_executor.submit(MangaOcr) | ||
|
||
with futures.ThreadPoolExecutor( | ||
max_workers=1, initializer=copilot.initialize | ||
) as copilot_executor: | ||
for _ in range(copilot_executor._max_workers): | ||
copilot_executor.submit(lambda: None) # to pre-initialize threads | ||
|
||
class Api: | ||
def detect(self, img_b64: str): | ||
img_bytes = base64.b64decode(img_b64) | ||
img_array = np.frombuffer(img_bytes, np.uint8) | ||
img_cv2 = cv2.imdecode(img_array, cv2.IMREAD_COLOR) | ||
img_cv2 = cv2.cvtColor(img_cv2, cv2.COLOR_BGR2RGB) | ||
img_mp = mp.Image(image_format=mp.ImageFormat.SRGB, data=img_cv2) | ||
return to_dict(detector.detect(img_mp)) | ||
|
||
def ocr(self, img_b64: str): | ||
img_bytes = base64.b64decode(img_b64) | ||
with Image.open(io.BytesIO(img_bytes)) as img: | ||
mocr = future_mocr.result() | ||
mocr_executor.shutdown() | ||
return mocr(img) | ||
|
||
def translate(self, texts: list[str], language: str): | ||
joined_texts = "\n".join(texts) | ||
joined_translations = translators.translate_text( | ||
joined_texts, to_language=language, translator="google" | ||
) | ||
return joined_translations.split("\n") | ||
|
||
def translate_copilot(self, texts: list[str], language: str): | ||
return copilot_executor.submit( | ||
copilot.translate, texts, language | ||
).result() | ||
|
||
# fix https://github.com/python/cpython/issues/88141 | ||
mime.add_type("text/javascript", ".js") | ||
|
||
webview.create_window( | ||
"Transmanga", | ||
pathlib.Path(__file__, "../client/dist/index.html").as_posix(), | ||
js_api=Api(), | ||
maximized=True, | ||
) | ||
webview.start(private_mode=False, debug=os.environ.get("DEBUG") == "1") | ||
|
||
|
||
def to_dict(obj): | ||
return json.loads(json.dumps(obj, default=lambda o: getattr(o, "__dict__", str(o)))) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
## Usage | ||
|
||
```bash | ||
$ npm install # or pnpm install or yarn install | ||
``` | ||
|
||
### Learn more on the [Solid Website](https://solidjs.com) and come chat with us on our [Discord](https://discord.com/invite/solidjs) | ||
|
||
## Available Scripts | ||
|
||
In the project directory, you can run: | ||
|
||
### `npm run dev` | ||
|
||
Runs the app in the development mode.<br> | ||
Open [http://localhost:5173](http://localhost:5173) to view it in the browser. | ||
|
||
### `npm run build` | ||
|
||
Builds the app for production to the `dist` folder.<br> | ||
It correctly bundles Solid in production mode and optimizes the build for the best performance. | ||
|
||
The build is minified and the filenames include the hashes.<br> | ||
Your app is ready to be deployed! | ||
|
||
## Deployment | ||
|
||
Learn more about deploying your application with the [documentations](https://vitejs.dev/guide/static-deploy.html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Transmanga</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/index.jsx"></script> | ||
</body> | ||
</html> |
Oops, something went wrong.