Spaces:
Runtime error
Runtime error
Commit
·
c66a76d
0
Parent(s):
Duplicate from luca-martial/neural-style-transfer
Browse filesCo-authored-by: Luca Martial <luca-martial@users.noreply.huggingface.co>
- .gitattributes +27 -0
- README.md +38 -0
- app.py +49 -0
- example_aristotle.jpeg +0 -0
- example_avatar.jpeg +0 -0
- example_dali.jpeg +0 -0
- example_einstein.jpeg +0 -0
- example_joker.jpeg +0 -0
- example_paris.jpeg +0 -0
- example_polasticot1.jpeg +0 -0
- example_polasticot2.jpeg +0 -0
- example_polasticot3.jpeg +0 -0
- example_vangogh.jpeg +0 -0
- requirements.txt +4 -0
.gitattributes
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bin.* filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Neural Style Transfer
|
| 3 |
+
emoji: 💩
|
| 4 |
+
colorFrom: pink
|
| 5 |
+
colorTo: red
|
| 6 |
+
sdk: gradio
|
| 7 |
+
app_file: app.py
|
| 8 |
+
pinned: false
|
| 9 |
+
duplicated_from: luca-martial/neural-style-transfer
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# Configuration
|
| 13 |
+
|
| 14 |
+
`title`: _string_
|
| 15 |
+
Display title for the Space
|
| 16 |
+
|
| 17 |
+
`emoji`: _string_
|
| 18 |
+
Space emoji (emoji-only character allowed)
|
| 19 |
+
|
| 20 |
+
`colorFrom`: _string_
|
| 21 |
+
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
|
| 22 |
+
|
| 23 |
+
`colorTo`: _string_
|
| 24 |
+
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
|
| 25 |
+
|
| 26 |
+
`sdk`: _string_
|
| 27 |
+
Can be either `gradio` or `streamlit`
|
| 28 |
+
|
| 29 |
+
`sdk_version` : _string_
|
| 30 |
+
Only applicable for `streamlit` SDK.
|
| 31 |
+
See [doc](https://hf.co/docs/hub/spaces) for more info on supported versions.
|
| 32 |
+
|
| 33 |
+
`app_file`: _string_
|
| 34 |
+
Path to your main application file (which contains either `gradio` or `streamlit` Python code).
|
| 35 |
+
Path is relative to the root of the repository.
|
| 36 |
+
|
| 37 |
+
`pinned`: _boolean_
|
| 38 |
+
Whether the Space stays on top of your list.
|
app.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import tensorflow_hub as hub
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
import numpy as np
|
| 6 |
+
import PIL.Image
|
| 7 |
+
|
| 8 |
+
# Load model from TF-Hub
|
| 9 |
+
hub_model = hub.load('https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/2')
|
| 10 |
+
|
| 11 |
+
# Function to convert tensor to image
|
| 12 |
+
def tensor_to_image(tensor):
|
| 13 |
+
tensor = tensor*255
|
| 14 |
+
tensor = np.array(tensor, dtype=np.uint8)
|
| 15 |
+
if np.ndim(tensor)>3:
|
| 16 |
+
assert tensor.shape[0] == 1
|
| 17 |
+
tensor = tensor[0]
|
| 18 |
+
return PIL.Image.fromarray(tensor)
|
| 19 |
+
|
| 20 |
+
# Stylize function
|
| 21 |
+
def stylize(content_image, style_image):
|
| 22 |
+
# Convert to float32 numpy array, add batch dimension, and normalize to range [0, 1]. Example using numpy:
|
| 23 |
+
content_image = content_image.astype(np.float32)[np.newaxis, ...] / 255.
|
| 24 |
+
style_image = style_image.astype(np.float32)[np.newaxis, ...] / 255.
|
| 25 |
+
# Stylize image
|
| 26 |
+
stylized_image = hub_model(tf.constant(content_image), tf.constant(style_image))[0]
|
| 27 |
+
return tensor_to_image(stylized_image)
|
| 28 |
+
|
| 29 |
+
# Add image examples for users
|
| 30 |
+
joker = ["example_joker.jpeg", "example_polasticot1.jpeg"]
|
| 31 |
+
paris = ["example_paris.jpeg", "example_vangogh.jpeg"]
|
| 32 |
+
einstein = ["example_einstein.jpeg", "example_polasticot2.jpeg"]
|
| 33 |
+
|
| 34 |
+
# Customize interface
|
| 35 |
+
title = "Fast Neural Style Transfer using TF-Hub"
|
| 36 |
+
description = "Demo for neural style transfer using the pretrained Arbitrary Image Stylization model from TensorFlow Hub."
|
| 37 |
+
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/1705.06830'>Exploring the structure of a real-time, arbitrary neural artistic stylization network</a></p>"
|
| 38 |
+
content_input = gr.inputs.Image(label="Content Image", source="upload")
|
| 39 |
+
style_input = gr.inputs.Image(label="Style Image", source="upload")
|
| 40 |
+
|
| 41 |
+
# Build and launch
|
| 42 |
+
iface = gr.Interface(fn=stylize,
|
| 43 |
+
inputs=[content_input, style_input],
|
| 44 |
+
outputs="image",
|
| 45 |
+
title=title,
|
| 46 |
+
description=description,
|
| 47 |
+
article=article,
|
| 48 |
+
examples=[joker, paris, einstein])
|
| 49 |
+
iface.launch()
|
example_aristotle.jpeg
ADDED
|
example_avatar.jpeg
ADDED
|
|
example_dali.jpeg
ADDED
|
example_einstein.jpeg
ADDED
|
example_joker.jpeg
ADDED
|
example_paris.jpeg
ADDED
|
example_polasticot1.jpeg
ADDED
|
example_polasticot2.jpeg
ADDED
|
example_polasticot3.jpeg
ADDED
|
example_vangogh.jpeg
ADDED
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
numpy
|
| 2 |
+
matplotlib
|
| 3 |
+
tensorflow
|
| 4 |
+
tensorflow_hub
|