DenisT's picture
converted app into gradio application, made faster
7cf86f8
raw
history blame
1.21 kB
import numpy as np
from PIL import Image
import gradio as gr
from main import predict
def process_image(image):
if image is not None:
if not isinstance(image, np.ndarray):
image = np.array(Image.open(image))
print(image)
translated_image = predict(image)
return translated_image
return None
with gr.Blocks() as demo:
gr.Markdown(
"""
<div style="display: flex; align-items: center; flex-direction: row; justify-content: center; margin-bottom: 20px; text-align: center;">
<a href="https://github.com/Detopall/manga-translator" target="_blank" rel="noopener noreferrer" style="text-decoration: none;">
<h1 style="display: inline; margin-left: 10px; text-decoration: underline;">Manga Translator</h1>
</a>
</div>
"""
)
with gr.Row():
with gr.Column(scale=1):
image_input = gr.Image()
submit_button = gr.Button("Translate")
with gr.Column(scale=1):
image_output = gr.Image()
submit_button.click(process_image, inputs=image_input, outputs=image_output)
examples = gr.Examples(examples=[
["./examples/ex1.jpg"],
["./examples/ex2.jpg"],
["./examples/ex3.jpg"],
["./examples/ex4.jpg"],
], inputs=image_input)
if __name__ == "__main__":
demo.launch()