Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Model path...
|
| 2 |
+
edges2ferrets = '/content/drive/MyDrive/DMLAP_FINAL/models/edges2ferrets_ver2.2/e299999_generator.h5'
|
| 3 |
+
|
| 4 |
+
# Load the Pix2Pix generator model
|
| 5 |
+
ferretMaker = tf.keras.models.load_model(edges2ferrets)
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def transform_image(img):
|
| 9 |
+
# Applies CV2 transformation to input doodle
|
| 10 |
+
grey_img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
|
| 11 |
+
processed_input = cv2.merge([grey_img, grey_img, grey_img])
|
| 12 |
+
|
| 13 |
+
# Ferret-ing the input!
|
| 14 |
+
processed_input = (processed_input - 127.5) / 127.5
|
| 15 |
+
result = ferretMaker(np.expand_dims(processed_input, 0), training=True)[0].numpy()
|
| 16 |
+
generated_ferret = (result * 0.5 + 0.5) * 255.0
|
| 17 |
+
|
| 18 |
+
return generated_ferret.astype(np.uint8)
|
| 19 |
+
|
| 20 |
+
iface = gr.Interface(
|
| 21 |
+
fn=transform_image,
|
| 22 |
+
inputs=gr.Image(type="numpy", image_mode="RGB"),
|
| 23 |
+
outputs=gr.Image(type="numpy", image_mode="RGB"),
|
| 24 |
+
live=True,
|
| 25 |
+
title="Edges2Ferrets generation!",
|
| 26 |
+
description="Upload a doodle to create a ferret!",
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
iface.launch(share=True)
|