Spaces:
Runtime error
Runtime error
add some diff
Browse files
app.py
CHANGED
@@ -1,7 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
def greet(name):
|
4 |
-
return "Hello " + name + "!!"
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import tensorflow as tf
|
3 |
+
# Load compressed models from tensorflow_hub
|
4 |
+
os.environ['TFHUB_MODEL_LOAD_FORMAT'] = 'COMPRESSED'
|
5 |
+
|
6 |
+
import numpy as np
|
7 |
+
import PIL.Image
|
8 |
+
import time
|
9 |
+
import functools
|
10 |
+
|
11 |
+
|
12 |
+
|
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 |
+
import tensorflow_hub as hub
|
22 |
+
hub_model = hub.load('https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/2')
|
23 |
+
|
24 |
import gradio as gr
|
25 |
|
|
|
|
|
26 |
|
27 |
+
def inference(content_image, style_image):
|
28 |
+
stylized_image = hub_model(tf.constant(content_image), tf.constant(style_image))[0]
|
29 |
+
img = tensor_to_image(stylized_image)
|
30 |
+
return img
|
31 |
+
|
32 |
+
|
33 |
+
title = "TTT"
|
34 |
+
|
35 |
+
gr.Interface(
|
36 |
+
inference,
|
37 |
+
gr.inputs.Image(type="pil", label="content_image"),
|
38 |
+
gr.inputs.Image(type="pil", label="style_image"),
|
39 |
+
gr.outputs.Image(type="pil", label="Output"),
|
40 |
+
title=title,
|
41 |
+
description="",
|
42 |
+
enable_queue=True,
|
43 |
+
allow_flagging=False
|
44 |
+
).launch()
|
45 |
+
|
46 |
+
|