import os
import cv2
import gradio as gr
import AnimeGANv3_src
os.makedirs('output', exist_ok=True)
def inference(img_path, Style, if_face=None):
print(img_path, Style, if_face)
try:
img = cv2.imread(img_path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
if Style == "AnimeGANv3_Arcane":
f = "A"
if Style == "AnimeGANv3_Trump":
f = "T"
elif Style == "AnimeGANv3_Shinkai":
f = "S"
elif Style == "AnimeGANv3_PortraitSketch":
f = "P"
elif Style == "AnimeGANv3_Hayao":
f = "H"
else:
f = "U"
try:
det_face = True if if_face=="Yes" else False
output = AnimeGANv3_src.Convert(img, f, det_face)
save_path = f"output/out.{img_path.rsplit('.')[-1]}"
cv2.imwrite(save_path, output[:, :, ::-1])
return output, save_path
except RuntimeError as error:
print('Error', error)
except Exception as error:
print('global exception', error)
return None, None
title = "AnimeGANv3: To produce your own animation."
description = r"""Official online demo for AnimeGANv3. If you like what I'm doing you can tip me on **patreon**.
It can be used to turn your photos or videos into anime.
To use it, simply upload your image. It can convert landscape photos to Hayao Miyazaki or Makoto Shinkai style anime, as well as 4 style conversions about human faces.
If AnimeGANv3 is helpful, please help to ⭐ the Github Repo and recommend it to your friends. 😊
"""
article = r"""
[![GitHub Stars](https://img.shields.io/github/stars/TachibanaYoshino/AnimeGANv3?style=social)](https://github.com/TachibanaYoshino/AnimeGANv3)
### 🗻 Demo: Video to anime (Hayao Style)