|
from towhee import pipeline, FileManagerConfig, FileManager |
|
import gradio |
|
import numpy |
|
from PIL import Image |
|
|
|
title = 'Towhee AnimeGanV2 Pipeline' |
|
description = 'An end to end pipeline for AnimeGanV2 using the Towhee framework. Take a look at `app.py` to see how little steps it takes and try it for yourself using `pip install towhee`.\nQuick Note: First run after reboot may be slow due to caching pipeline operators.' |
|
article = '<a href="https://github.com/towhee-io/towhee" style="text-align:center" target="_blank">Check out the Towhee Github</a>' |
|
|
|
|
|
size = (512, 512) |
|
|
|
|
|
fmc = FileManagerConfig() |
|
fmc.update_default_cache('./') |
|
|
|
|
|
celeba = pipeline('filip-halt/style-transfer-animegan', tag = 'celeba') |
|
facepaintv1 = pipeline('filip-halt/style-transfer-animegan', tag = 'facepaintv1') |
|
facepaintv2 = pipeline('filip-halt/style-transfer-animegan', tag = 'facepaintv2') |
|
hayao = pipeline('filip-halt/style-transfer-animegan', tag = 'hayao') |
|
paprika = pipeline('filip-halt/style-transfer-animegan', tag = 'paprika') |
|
shinkai = pipeline('filip-halt/style-transfer-animegan', tag = 'shinkai') |
|
|
|
def operation(Input, Version): |
|
|
|
Input.thumbnail(size, Image.ANTIALIAS) |
|
|
|
|
|
|
|
Input.save('./test.jpg') |
|
|
|
if Version == 'celeba': |
|
x = celeba('./test.jpg') |
|
elif Version == 'facepaintv1': |
|
x = facepaintv1('./test.jpg') |
|
elif Version == 'facepaintv2': |
|
x = facepaintv2('./test.jpg') |
|
elif Version == 'hayao': |
|
x = hayao('./test.jpg') |
|
elif Version == 'paprika': |
|
x = paprika('./test.jpg') |
|
elif Version == 'shinkai': |
|
x = shinkai('./test.jpg') |
|
|
|
|
|
x = numpy.transpose(x[0][0], (1,2,0)) |
|
x = Image.fromarray((x * 255).astype(numpy.uint8)) |
|
return x |
|
|
|
gradio.Interface(operation, [gradio.inputs.Image(type="pil"), gradio.inputs.Radio(["celeba", "facepaintv1", "facepaintv2", "hayao", "paprika", 'shinkai'])], gradio.outputs.Image(type="pil"), allow_flagging=False,allow_screenshot=False, title=title, article=article, description=description).launch(enable_queue=True) |
|
|