Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,6 @@
|
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
import tensorflow as tf
|
| 5 |
-
# import os
|
| 6 |
import tensorflow_hub as hub
|
| 7 |
import PIL
|
| 8 |
from PIL import Image,ImageOps
|
|
@@ -38,25 +37,9 @@ def tensor_to_image(tensor):
|
|
| 38 |
tensor = tensor[0]
|
| 39 |
return PIL.Image.fromarray(tensor)
|
| 40 |
|
| 41 |
-
"""##Saving unscaled Tensor images."""
|
| 42 |
-
|
| 43 |
-
def save_image(image, filename):
|
| 44 |
-
"""
|
| 45 |
-
Saves unscaled Tensor Images.
|
| 46 |
-
Args:
|
| 47 |
-
image: 3D image tensor. [height, width, channels]
|
| 48 |
-
filename: Name of the file to save to.
|
| 49 |
-
"""
|
| 50 |
-
if not isinstance(image, Image.Image):
|
| 51 |
-
image = tf.clip_by_value(image, 0, 255)
|
| 52 |
-
image = Image.fromarray(tf.cast(image, tf.uint8).numpy())
|
| 53 |
-
image.save("%s.jpg" % filename)
|
| 54 |
-
print("Saved as %s.jpg" % filename)
|
| 55 |
-
|
| 56 |
-
"""## Grayscaling image for testing purpose to check if we could get better results."""
|
| 57 |
-
|
| 58 |
|
| 59 |
|
|
|
|
| 60 |
def gray_scaled(inp_img):
|
| 61 |
gray = cv2.cvtColor(inp_img, cv2.COLOR_BGR2GRAY)
|
| 62 |
gray_img = np.zeros_like(inp_img)
|
|
@@ -65,6 +48,7 @@ def gray_scaled(inp_img):
|
|
| 65 |
gray_img[:,:,2] = gray
|
| 66 |
return gray_img
|
| 67 |
|
|
|
|
| 68 |
def transform_mymodel(content_image,style_image):
|
| 69 |
# Convert to float32 numpy array, add batch dimension, and normalize to range [0, 1]
|
| 70 |
#content_image=gray_scaled(content_image)
|
|
@@ -86,8 +70,8 @@ def gradio_intrface(mymodel):
|
|
| 86 |
# Initializing the input component
|
| 87 |
image1 = gr.inputs.Image(label="Content Image") #CONTENT IMAGE
|
| 88 |
image2 = gr.inputs.Image(label="Style Image") #STYLE IMAGE
|
| 89 |
-
stylizedimg=gr.outputs.Image()
|
| 90 |
-
gr.Interface(fn=mymodel, inputs= [image1,image2] , outputs= stylizedimg,title='Style Transfer',theme='seafoam',examples=[['Content_Images/contnt12.jpg','VG516.jpg']],article="
|
| 91 |
|
| 92 |
"""The function will be launched both Inline and Outline where u need to add a content and style image."""
|
| 93 |
|
|
|
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
import tensorflow as tf
|
|
|
|
| 5 |
import tensorflow_hub as hub
|
| 6 |
import PIL
|
| 7 |
from PIL import Image,ImageOps
|
|
|
|
| 37 |
tensor = tensor[0]
|
| 38 |
return PIL.Image.fromarray(tensor)
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
|
| 42 |
+
"""## Grayscaling image for testing purpose to check if we could get better results."""
|
| 43 |
def gray_scaled(inp_img):
|
| 44 |
gray = cv2.cvtColor(inp_img, cv2.COLOR_BGR2GRAY)
|
| 45 |
gray_img = np.zeros_like(inp_img)
|
|
|
|
| 48 |
gray_img[:,:,2] = gray
|
| 49 |
return gray_img
|
| 50 |
|
| 51 |
+
##Transformation
|
| 52 |
def transform_mymodel(content_image,style_image):
|
| 53 |
# Convert to float32 numpy array, add batch dimension, and normalize to range [0, 1]
|
| 54 |
#content_image=gray_scaled(content_image)
|
|
|
|
| 70 |
# Initializing the input component
|
| 71 |
image1 = gr.inputs.Image(label="Content Image") #CONTENT IMAGE
|
| 72 |
image2 = gr.inputs.Image(label="Style Image") #STYLE IMAGE
|
| 73 |
+
stylizedimg=gr.outputs.Image(label="Result")
|
| 74 |
+
gr.Interface(fn=mymodel, inputs= [image1,image2] , outputs= stylizedimg,title='Style Transfer',theme='seafoam',examples=[['Content_Images/contnt12.jpg','VG516.jpg']],article="References-\n\n""<a href='https://www.tensorflow.org/hub/tutorials/tf2_arbitrary_image_stylization'>\n").launch()
|
| 75 |
|
| 76 |
"""The function will be launched both Inline and Outline where u need to add a content and style image."""
|
| 77 |
|