Spaces:
Build error
Build error
Commit ·
0aec38d
0
Parent(s):
Duplicate from nightfury/Neural_Style_Transfer
Browse filesCo-authored-by: spartan <nightfury@users.noreply.huggingface.co>
- .gitattributes +36 -0
- README.md +36 -0
- app.py +61 -0
- example_avatar.jpeg +0 -0
- example_deadpool.png +0 -0
- example_deadpool2.jpeg +0 -0
- example_einstein.jpeg +0 -0
- example_joker.jpeg +0 -0
- example_mona1.jpeg +0 -0
- example_paris.jpeg +0 -0
- requirements.txt +4 -0
- style_polasticot1.jpeg +0 -0
- style_polasticot2.jpeg +0 -0
- style_polasticot3.jpeg +0 -0
- style_starry_night.jpeg +0 -0
- style_the_great_wave.jpeg +3 -0
- style_the_scream.jpg +3 -0
- style_vangogh.jpeg +0 -0
.gitattributes
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt 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 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
style_the_great_wave.jpeg filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
style_the_scream.jpg filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Neural Style Transfer
|
| 3 |
+
emoji: 💻
|
| 4 |
+
colorFrom: gray
|
| 5 |
+
colorTo: green
|
| 6 |
+
sdk: gradio
|
| 7 |
+
app_file: app.py
|
| 8 |
+
pinned: false
|
| 9 |
+
license: mit
|
| 10 |
+
duplicated_from: nightfury/Neural_Style_Transfer
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
| 14 |
+
|
| 15 |
+
# Configuration
|
| 16 |
+
`title`: _string_
|
| 17 |
+
Display title for the Space
|
| 18 |
+
`emoji`: _string_
|
| 19 |
+
Space emoji (emoji-only character allowed)
|
| 20 |
+
`colorFrom`: _string_
|
| 21 |
+
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
|
| 22 |
+
`colorTo`: _string_
|
| 23 |
+
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
|
| 24 |
+
`sdk`: _string_
|
| 25 |
+
Can be either `gradio` or `streamlit`
|
| 26 |
+
`sdk_version` : _string_
|
| 27 |
+
Only applicable for `streamlit` SDK.
|
| 28 |
+
See [doc](https://hf.co/docs/hub/spaces) for more info on supported versions.
|
| 29 |
+
|
| 30 |
+
`app_file`: _string_
|
| 31 |
+
Path to your main application file (which contains either `gradio` or `streamlit` Python code).
|
| 32 |
+
Path is relative to the root of the repository.
|
| 33 |
+
|
| 34 |
+
`pinned`: _boolean_
|
| 35 |
+
Whether the Space stays on top of your list.
|
| 36 |
+
|
app.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import tensorflow as tf
|
| 5 |
+
import tensorflow_hub as hub
|
| 6 |
+
|
| 7 |
+
# Load model from TF-Hub
|
| 8 |
+
style_transfer_model = hub.load("https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/2")
|
| 9 |
+
|
| 10 |
+
# function to Stylize the Image or to perform a style transfer
|
| 11 |
+
def do_style_transfer(content_image, style_image):
|
| 12 |
+
# Convert to float32 numpy array, add batch dimension, and normalize to range [0, 1]. Example using numpy:
|
| 13 |
+
content_image = tf.convert_to_tensor(content_image, np.float32)[tf.newaxis, ...] / 255.
|
| 14 |
+
style_image = tf.convert_to_tensor(style_image, np.float32)[tf.newaxis, ...] / 255.
|
| 15 |
+
# Stylize image
|
| 16 |
+
output = style_transfer_model(content_image, style_image)
|
| 17 |
+
stylized_image = output[0]
|
| 18 |
+
|
| 19 |
+
return Image.fromarray(np.uint8(stylized_image[0] * 255))
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
content_image_input = gr.inputs.Image(label="Content Image")
|
| 23 |
+
style_image_input = gr.inputs.Image(shape=(256, 256), label="Style Image")
|
| 24 |
+
|
| 25 |
+
# Add image examples for users
|
| 26 |
+
golden_gate = ["example_deadpool2.jpeg", "style_the_great_wave.jpeg"]
|
| 27 |
+
joshua_tree = ["example_deadpool.png", "style_starry_night.jpeg"]
|
| 28 |
+
avatar = ["example_avatar.jpeg", "style_the_scream.jpg"]
|
| 29 |
+
joker = ["example_joker.jpeg", "style_polasticot1.jpeg"]
|
| 30 |
+
einstein = ["example_einstein.jpeg", "style_polasticot2.jpeg"]
|
| 31 |
+
monalisa = ["example_mona1.jpeg", "style_polasticot3.jpeg"]
|
| 32 |
+
paris = ["example_paris.jpeg", "style_vangogh.jpeg"]
|
| 33 |
+
|
| 34 |
+
# Customize interface
|
| 35 |
+
title = "Fast Neural Style Transfer using TF-Hub"
|
| 36 |
+
description = "<p style='text-align: center'> Demo for Neural Style Transfer using a pretrained Arbitrary Image Stylization model from TensorFlow Hub. To use it, simply upload a content image and style image, or click one of the examples to load them. To learn more about the project, please find the references listed below.</p>"
|
| 37 |
+
article = r"""<b>:: References ::</b>
|
| 38 |
+
<br>
|
| 39 |
+
<a href='https://www.tensorflow.org/hub/tutorials/tf2_arbitrary_image_stylization' target='_blank'>
|
| 40 |
+
Tutorial to implement Fast Neural Style Transfer using the pretrained model from TensorFlow Hub
|
| 41 |
+
</a>
|
| 42 |
+
<br>
|
| 43 |
+
<a href='https://arxiv.org/abs/1705.06830'>
|
| 44 |
+
Exploring the structure of a real-time, arbitrary neural artistic stylization network
|
| 45 |
+
</a>
|
| 46 |
+
<br>
|
| 47 |
+
<center><img src='https://visitor-badge.glitch.me/badge?page_id=dj_arbi_img_stylization' alt='visitor badge'></center>
|
| 48 |
+
"""
|
| 49 |
+
|
| 50 |
+
content_input = gr.inputs.Image(label="Content Image", source="upload")
|
| 51 |
+
style_input = gr.inputs.Image(label="Style Image", source="upload")
|
| 52 |
+
|
| 53 |
+
app_interface = gr.Interface(fn=do_style_transfer,
|
| 54 |
+
inputs=[content_image_input, style_image_input],
|
| 55 |
+
outputs="image",
|
| 56 |
+
title=title,
|
| 57 |
+
description=description,
|
| 58 |
+
examples=[golden_gate,joshua_tree,avatar,joker,einstein,monalisa,paris],
|
| 59 |
+
article=article
|
| 60 |
+
)
|
| 61 |
+
app_interface.launch()
|
example_avatar.jpeg
ADDED
|
|
example_deadpool.png
ADDED
|
example_deadpool2.jpeg
ADDED
|
example_einstein.jpeg
ADDED
|
example_joker.jpeg
ADDED
|
example_mona1.jpeg
ADDED
|
example_paris.jpeg
ADDED
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
matplotlib
|
| 2 |
+
numpy==1.21.2
|
| 3 |
+
tensorflow==2.2.0
|
| 4 |
+
tensorflow_hub==0.12.0
|
style_polasticot1.jpeg
ADDED
|
style_polasticot2.jpeg
ADDED
|
style_polasticot3.jpeg
ADDED
|
style_starry_night.jpeg
ADDED
|
style_the_great_wave.jpeg
ADDED
|
Git LFS Details
|
style_the_scream.jpg
ADDED
|
Git LFS Details
|
style_vangogh.jpeg
ADDED
|