ebhon commited on
Commit
8be7717
·
verified ·
1 Parent(s): d2c0646

Manga Translator V1.0

Browse files
Files changed (4) hide show
  1. .streamlit/config.toml +10 -0
  2. app.py +139 -0
  3. best.pt +3 -0
  4. requirements.txt +12 -0
.streamlit/config.toml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ [theme]
2
+ primaryColor = "#FF4B4B"
3
+ backgroundColor = "#FFFFFF"
4
+ secondaryBackgroundColor = "#F0F2F6"
5
+ textColor = "#262730"
6
+ font = "sans serif"
7
+
8
+ [server]
9
+ enableCORS = false
10
+ enableXsrfProtection = false
app.py ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ from PIL import Image
4
+ import torch
5
+ from manga_translator import process_manga_pages
6
+ import tempfile
7
+ from dotenv import load_dotenv
8
+
9
+ # Load environment variables
10
+ load_dotenv()
11
+
12
+ # Check for DeepL API key
13
+ DEEPL_API_KEY = os.getenv('DEEPL_API_KEY')
14
+ if not DEEPL_API_KEY:
15
+ st.warning("⚠️ DeepL API key not found. Using free translation service which may have limitations.")
16
+
17
+ st.set_page_config(
18
+ page_title="Manga Translator",
19
+ page_icon="📚",
20
+ layout="wide"
21
+ )
22
+
23
+ st.title("🎯 Manga Translator")
24
+
25
+ # Main description
26
+ st.markdown("""
27
+ This app uses custom YOLO detection, OCR, and machine translation to automatically translate manga pages from Japanese to English.
28
+
29
+ ⚠️ **Note**: Translation accuracy may vary due to the complexity of Japanese text and manga-specific expressions.
30
+ We're continuously working to improve the system!
31
+ """)
32
+
33
+ # Guidelines section before upload
34
+ st.markdown("""
35
+ ### 📋 Guidelines for Best Results
36
+ 1. **Image Requirements**:
37
+ - Clear, high-resolution manga page
38
+ - Japanese text should be clearly visible
39
+ - Text bubbles should not be cropped
40
+ - Supported formats: PNG, JPG, JPEG
41
+
42
+ 2. **For Best Results**:
43
+ - Avoid pages with handwritten text
44
+ - Ensure text bubbles are not overlapping
45
+ - Image should be properly oriented
46
+ - Avoid heavily compressed images
47
+
48
+ 3. **Privacy & Copyright**:
49
+ - Only upload content you have rights to use
50
+ - We don't store any uploaded images
51
+ - All processing is done in real-time
52
+ """)
53
+
54
+ # Technical demonstration
55
+ st.markdown("""
56
+ ### 🔍 How It Works
57
+ 1. **Text Detection**: Custom YOLO model detects text bubbles
58
+ 2. **OCR Processing**: Extracts Japanese text
59
+ 3. **Translation**: Converts to English using DeepL API
60
+ 4. **Text Insertion**: Places translated text back into the image
61
+ """)
62
+
63
+ # File uploader
64
+ uploaded_file = st.file_uploader("Choose a manga page (PNG, JPG)", type=['png', 'jpg', 'jpeg'])
65
+
66
+ if uploaded_file is not None:
67
+ # Create temporary directories for processing
68
+ with tempfile.TemporaryDirectory() as temp_dir:
69
+ # Save uploaded file
70
+ input_path = os.path.join(temp_dir, "input")
71
+ output_path = os.path.join(temp_dir, "output")
72
+ os.makedirs(input_path, exist_ok=True)
73
+ os.makedirs(output_path, exist_ok=True)
74
+
75
+ temp_file = os.path.join(input_path, uploaded_file.name)
76
+ with open(temp_file, "wb") as f:
77
+ f.write(uploaded_file.getbuffer())
78
+
79
+ # Process the image
80
+ with st.spinner("Translating manga... Please wait."):
81
+ try:
82
+ process_manga_pages(
83
+ image_folder=input_path,
84
+ translated_dir=output_path,
85
+ show_results=False
86
+ )
87
+
88
+ # Display results
89
+ col1, col2 = st.columns(2)
90
+
91
+ with col1:
92
+ st.subheader("Original")
93
+ original_image = Image.open(temp_file)
94
+ st.image(original_image, use_column_width=True)
95
+
96
+ with col2:
97
+ st.subheader("Translated")
98
+ translated_file = os.path.join(output_path, uploaded_file.name)
99
+ if os.path.exists(translated_file):
100
+ translated_image = Image.open(translated_file)
101
+ st.image(translated_image, use_column_width=True)
102
+ else:
103
+ st.error("Translation failed. Please try another image.")
104
+
105
+ except Exception as e:
106
+ st.error(f"An error occurred: {str(e)}")
107
+
108
+ # Add information about the project
109
+ st.markdown("""
110
+ ---
111
+ ## About the Project
112
+
113
+ This manga translator uses:
114
+ - Custom-trained YOLO model for text bubble detection
115
+ - MangaOCR for Japanese text extraction
116
+ - DeepL API for high-quality translation
117
+ - OpenCV and PIL for image processing
118
+
119
+ ### Technical Details
120
+ - Supports single page translation
121
+ - Real-time processing
122
+ - No image storage
123
+ - Privacy-focused design
124
+
125
+ ### Links
126
+ - [GitHub Repository](https://github.com/ebhon/manga_translator_project)
127
+ - [YOLO Model Repository](https://github.com/ebhon/YOLO-manga-bubble-detector)
128
+
129
+ ### Feedback
130
+ Found a bug or have a suggestion? Please open an issue on GitHub!
131
+ """)
132
+
133
+ # Add footer with disclaimer
134
+ st.markdown("""
135
+ ---
136
+ Created by [Handwitanto Abraham](https://www.linkedin.com/in/handwitanto-abraham/)
137
+
138
+ *Disclaimer: This tool is for educational purposes only. Users are responsible for ensuring they have the right to translate any content they upload.*
139
+ """)
best.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3e85e7193d70b24719394a5a597a0c2f2e1f6aaa6c6e11d9c9e47d1945ba681e
3
+ size 6233315
requirements.txt ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ manga-ocr>=0.1.0
2
+ torch>=2.0.0
3
+ transformers>=4.30.0
4
+ Pillow>=10.0.0
5
+ opencv-python>=4.8.0
6
+ numpy>=1.24.0
7
+ matplotlib>=3.7.0
8
+ deepl>=1.15.0
9
+ googletrans>=3.1.0a0
10
+ ultralytics>=8.0.0
11
+ streamlit>=1.28.0
12
+ python-dotenv>=1.0.0