Filip Haltmayer
commited on
Commit
·
a0a49ca
1
Parent(s):
3fc7f74
files
Browse files- README.md +4 -4
- app.py +51 -0
- packages.txt +4 -0
- requirements.txt +2 -0
README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
app_file: app.py
|
| 8 |
pinned: false
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Tow_test
|
| 3 |
+
emoji: 🚀
|
| 4 |
+
colorFrom: indigo
|
| 5 |
+
colorTo: blue
|
| 6 |
sdk: gradio
|
| 7 |
app_file: app.py
|
| 8 |
pinned: false
|
app.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from towhee import pipeline, FileManagerConfig, FileManager
|
| 2 |
+
import gradio
|
| 3 |
+
import numpy
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
title = 'Towhee AnimeGanV2 Pipeline'
|
| 7 |
+
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.'
|
| 8 |
+
article = '<a href="https://github.com/towhee-io/towhee" style="text-align:center" target="_blank">Check out the Towhee Github</a>'
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
size = (512, 512)
|
| 12 |
+
|
| 13 |
+
# Configuring the caching location
|
| 14 |
+
fmc = FileManagerConfig()
|
| 15 |
+
fmc.update_default_cache('./')
|
| 16 |
+
|
| 17 |
+
# All pipelines loaded in at start. These pipelines all share operators for reduced memory overhead.
|
| 18 |
+
celeba = pipeline('filip-halt/style-transfer-animegan', tag = 'celeba')
|
| 19 |
+
facepaintv1 = pipeline('filip-halt/style-transfer-animegan', tag = 'facepaintv1')
|
| 20 |
+
facepaintv2 = pipeline('filip-halt/style-transfer-animegan', tag = 'facepaintv2')
|
| 21 |
+
hayao = pipeline('filip-halt/style-transfer-animegan', tag = 'hayao')
|
| 22 |
+
paprika = pipeline('filip-halt/style-transfer-animegan', tag = 'paprika')
|
| 23 |
+
shinkai = pipeline('filip-halt/style-transfer-animegan', tag = 'shinkai')
|
| 24 |
+
|
| 25 |
+
def operation(Input, Version):
|
| 26 |
+
# Resizing the image while keeping aspect ratio.
|
| 27 |
+
Input.thumbnail(size, Image.ANTIALIAS)
|
| 28 |
+
# Saving image to file for input. Very low chance of concurrent file saves during the time
|
| 29 |
+
# between saving and taking first step of pipeline, so avoiding locks for now. In addition,
|
| 30 |
+
# current gradio is set to queue so there will never be parallel runs for this.
|
| 31 |
+
Input.save('./test.jpg')
|
| 32 |
+
|
| 33 |
+
if Version == 'celeba':
|
| 34 |
+
x = celeba('./test.jpg')
|
| 35 |
+
elif Version == 'facepaintv1':
|
| 36 |
+
x = facepaintv1('./test.jpg')
|
| 37 |
+
elif Version == 'facepaintv2':
|
| 38 |
+
x = facepaintv2('./test.jpg')
|
| 39 |
+
elif Version == 'hayao':
|
| 40 |
+
x = hayao('./test.jpg')
|
| 41 |
+
elif Version == 'paprika':
|
| 42 |
+
x = paprika('./test.jpg')
|
| 43 |
+
elif Version == 'shinkai':
|
| 44 |
+
x = shinkai('./test.jpg')
|
| 45 |
+
|
| 46 |
+
# Converting from channel-first, [0,1] value RGB, numpy array to PIL image.
|
| 47 |
+
x = numpy.transpose(x[0][0], (1,2,0))
|
| 48 |
+
x = Image.fromarray((x * 255).astype(numpy.uint8))
|
| 49 |
+
return x
|
| 50 |
+
|
| 51 |
+
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)
|
packages.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
python3-opencv
|
| 2 |
+
ffmpeg
|
| 3 |
+
libsm6
|
| 4 |
+
libxext6
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
-i https://test.pypi.org/simple/
|
| 2 |
+
towhee==0.4.1.dev46
|