drdata DarkCeptor44 commited on
Commit
1b49f52
·
0 Parent(s):

Duplicate from DarkCeptor44/neural-art

Browse files

Co-authored-by: Murilo Pagliuso <[email protected]>

.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
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ftz filter=lfs diff=lfs merge=lfs -text
6
+ *.gz filter=lfs diff=lfs merge=lfs -text
7
+ *.h5 filter=lfs diff=lfs merge=lfs -text
8
+ *.joblib filter=lfs diff=lfs merge=lfs -text
9
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
10
+ *.model filter=lfs diff=lfs merge=lfs -text
11
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
12
+ *.onnx filter=lfs diff=lfs merge=lfs -text
13
+ *.ot filter=lfs diff=lfs merge=lfs -text
14
+ *.parquet filter=lfs diff=lfs merge=lfs -text
15
+ *.pb filter=lfs diff=lfs merge=lfs -text
16
+ *.pt filter=lfs diff=lfs merge=lfs -text
17
+ *.pth filter=lfs diff=lfs merge=lfs -text
18
+ *.rar filter=lfs diff=lfs merge=lfs -text
19
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
20
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
21
+ *.tflite filter=lfs diff=lfs merge=lfs -text
22
+ *.tgz filter=lfs diff=lfs merge=lfs -text
23
+ *.wasm 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,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Neural Art
3
+ emoji: 🌖
4
+ colorFrom: pink
5
+ colorTo: red
6
+ sdk: gradio
7
+ sdk_version: 3.0.22
8
+ app_file: app.py
9
+ pinned: false
10
+ license: gpl-2.0
11
+ duplicated_from: DarkCeptor44/neural-art
12
+ ---
13
+ Original at https://huggingface.co/spaces/luca-martial/neural-style-transfer, maintained by me I guess since the original doesn't work any more
14
+
15
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
12
+ # Function to convert tensor to image
13
+ def tensor_to_image(tensor):
14
+ tensor = tensor * 255
15
+ tensor = np.array(tensor, dtype=np.uint8)
16
+ if np.ndim(tensor) > 3:
17
+ assert tensor.shape[0] == 1
18
+ tensor = tensor[0]
19
+ return PIL.Image.fromarray(tensor)
20
+
21
+
22
+ # Stylize function
23
+ def stylize(content_image, style_image):
24
+ # Convert to float32 numpy array, add batch dimension, and normalize to range [0, 1]. Example using numpy:
25
+ content_image = content_image.astype(np.float32)[np.newaxis, ...] / 255.
26
+ style_image = style_image.astype(np.float32)[np.newaxis, ...] / 255.
27
+ # Stylize image
28
+ stylized_image = hub_model(tf.constant(content_image), tf.constant(style_image))[0]
29
+ return tensor_to_image(stylized_image)
30
+
31
+
32
+ # Add image examples for users
33
+ joker = ["example_joker.jpeg", "example_polasticot1.jpeg"]
34
+ paris = ["example_paris.jpeg", "example_vangogh.jpeg"]
35
+ einstein = ["example_einstein.jpeg", "example_polasticot2.jpeg"]
36
+
37
+ # Customize interface
38
+ title = "Fast Neural Style Transfer using TF-Hub"
39
+ description = "Demo for neural style transfer using the pretrained Arbitrary Image Stylization model from TensorFlow Hub."
40
+ 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><p style='text-align: center'>Check out the <a href='https://huggingface.co/spaces/luca-martial/neural-style-transfer'>original space</a> although that one doesn't work</p>"
41
+ content_input = gr.inputs.Image(label="Content Image", source="upload")
42
+ style_input = gr.inputs.Image(label="Style Image", source="upload")
43
+
44
+ # Build and launch
45
+ iface = gr.Interface(fn=stylize,
46
+ inputs=[content_input, style_input],
47
+ outputs="image",
48
+ title=title,
49
+ description=description,
50
+ article=article,
51
+ examples=[joker, paris, einstein])
52
+ 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