Spaces:
Build error
Build error
ayaderaghul
commited on
Commit
•
683300a
1
Parent(s):
30417b2
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import keras
|
3 |
+
from keras.models import load_model
|
4 |
+
# from keras_contrib.layers.normalization.instancenormalization import InstanceNormalization
|
5 |
+
from tensorflow_addons.layers import InstanceNormalization
|
6 |
+
import matplotlib.pyplot as plt
|
7 |
+
import numpy as np
|
8 |
+
|
9 |
+
cust = {'InstanceNormalization': InstanceNormalization}
|
10 |
+
model=load_model('g_model_AtoB_002160.h5',cust)
|
11 |
+
path = [['ex1.jpg'], ['ex2.jpg']]
|
12 |
+
|
13 |
+
def show_preds_image(image_path):
|
14 |
+
A = plt.imread(image_path)
|
15 |
+
A = (A - 127.5) / 127.5
|
16 |
+
A = np.expand_dims(A,axis=0)
|
17 |
+
B = model.predict(A)
|
18 |
+
B=np.squeeze(B,axis=0)
|
19 |
+
B = (B + 1) / 2.0
|
20 |
+
return B
|
21 |
+
|
22 |
+
inputs_image = [
|
23 |
+
gr.components.Image(type="filepath", label="Input Image"),
|
24 |
+
]
|
25 |
+
outputs_image = [
|
26 |
+
gr.components.Image(type="numpy", label="Output Image"),
|
27 |
+
]
|
28 |
+
interface_image = gr.Interface(
|
29 |
+
fn=show_preds_image,
|
30 |
+
inputs=inputs_image,
|
31 |
+
outputs=outputs_image,
|
32 |
+
title="photo2monet",
|
33 |
+
examples=path,
|
34 |
+
cache_examples=False,
|
35 |
+
)
|
36 |
+
|
37 |
+
gr.TabbedInterface(
|
38 |
+
[interface_image],
|
39 |
+
tab_names=['Image inference']
|
40 |
+
).queue().launch()
|
41 |
+
|