Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,30 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
|
|
|
| 5 |
|
| 6 |
-
def style_transfer(
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
)
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
demo = gr.Interface(
|
| 14 |
fn=style_transfer,
|
| 15 |
-
inputs=[gr.Image(), gr.Image()],
|
| 16 |
outputs=gr.Image(),
|
| 17 |
-
title="Neural Style Transfer"
|
| 18 |
)
|
| 19 |
|
| 20 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import numpy as np
|
| 4 |
+
from PIL import Image
|
| 5 |
|
| 6 |
+
# Load your Keras model
|
| 7 |
+
model = tf.keras.models.load_model("NeuralStyleTransferModel.keras")
|
| 8 |
|
| 9 |
+
def style_transfer(content, style):
|
| 10 |
+
content = Image.fromarray(content).resize((256, 256))
|
| 11 |
+
style = Image.fromarray(style).resize((256, 256))
|
| 12 |
+
|
| 13 |
+
# preprocess (example: normalize, expand dims, etc.)
|
| 14 |
+
content_arr = np.expand_dims(np.array(content) / 255.0, axis=0)
|
| 15 |
+
style_arr = np.expand_dims(np.array(style) / 255.0, axis=0)
|
| 16 |
+
|
| 17 |
+
# run through your model
|
| 18 |
+
output = model.predict([content_arr, style_arr])
|
| 19 |
+
|
| 20 |
+
# postprocess
|
| 21 |
+
output_img = (output[0] * 255).astype("uint8")
|
| 22 |
+
return Image.fromarray(output_img)
|
| 23 |
|
| 24 |
demo = gr.Interface(
|
| 25 |
fn=style_transfer,
|
| 26 |
+
inputs=[gr.Image(type="numpy"), gr.Image(type="numpy")],
|
| 27 |
outputs=gr.Image(),
|
|
|
|
| 28 |
)
|
| 29 |
|
| 30 |
+
demo.launch()
|