ArsVie commited on
Commit
42b724a
·
verified ·
1 Parent(s): 98859df

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import shutil
3
+ import os
4
+ from MangaTranslator import MangaTranslator
5
+
6
+ # 1. Initialize the Translator (runs once on startup)
7
+ print("⏳ Initializing models... (This takes 30s)")
8
+ translator = MangaTranslator(
9
+ yolo_model_path='comic_yolov8m.pt',
10
+ translation_model="LiquidAI/LFM2-350M-ENJP-MT",
11
+ font_path="font.ttf"
12
+ )
13
+ print("✅ Models Ready!")
14
+
15
+ # 2. Define the Processing Function
16
+ def translate_manga(input_image):
17
+ if input_image is None:
18
+ return None
19
+
20
+ # Create temp paths for the pipeline
21
+ temp_in = "temp_input.jpg"
22
+ temp_out = "temp_output.jpg"
23
+
24
+ # Gradio gives us a PIL image, save it so your script can read it
25
+ input_image.save(temp_in)
26
+
27
+ # Run your existing pipeline
28
+ try:
29
+ translator.process_single_image(
30
+ image_path=temp_in,
31
+ output_path=temp_out,
32
+ series_info=None # No context for the demo
33
+ )
34
+ return temp_out
35
+ except Exception as e:
36
+ print(f"Error: {e}")
37
+ return input_image # Return original if fail
38
+
39
+ # 3. Launch the Interface
40
+ if __name__ == "__main__":
41
+ iface = gr.Interface(
42
+ fn=translate_manga,
43
+ inputs=gr.Image(type="pil", label="Upload Manga Page (Japanese)"),
44
+ outputs=gr.Image(type="filepath", label="Translated Page (English)"),
45
+ title="✨ LiquidAI Manga Translator (350M Demo)",
46
+ description="Running natively on CPU using Liquid LFM2-350M, MangaOCR, and LaMa Inpainting.",
47
+ examples=[["example.jpg"]] # Optional: If you upload an example image
48
+ )
49
+ iface.launch()