Sa-m commited on
Commit
e73fe2f
·
1 Parent(s): fa0bead

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -15
app.py CHANGED
@@ -18,7 +18,7 @@ import numpy as np
18
  #import requests
19
  #import tarfile
20
 
21
- MODEL_PATH='Nst_model'
22
 
23
  # Disable scientific notation for clarity
24
  np.set_printoptions(suppress=True)
@@ -39,7 +39,7 @@ def tensor_to_image(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)
@@ -47,13 +47,14 @@ def gray_scaled(inp_img):
47
  gray_img[:,:,1] = gray
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)
55
- content_image = content_image.astype(np.float32)[np.newaxis, ...] / 255.0
56
- style_image = style_image.astype(np.float32)[np.newaxis, ...] / 255.0
57
 
58
  #Resizing image
59
  #style_image = tf.image.resize(style_image, (256, 256))
@@ -66,17 +67,11 @@ def transform_mymodel(content_image,style_image):
66
  stylized_image =tensor_to_image(stylized_image)
67
  return stylized_image
68
 
69
- def gradio_intrface(mymodel):
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\nExploring the structure of a real-time, arbitrary neural artistic stylization network. Golnaz Ghiasi, Honglak Lee, Manjunath Kudlur, Vincent Dumoulin.").launch()
75
 
76
- """The function will be launched both Inline and Outline where u need to add a content and style image."""
77
-
78
-
79
- gradio_intrface(transform_mymodel)
80
 
81
 
82
 
 
18
  #import requests
19
  #import tarfile
20
 
21
+ #MODEL_PATH='Nst_model'
22
 
23
  # Disable scientific notation for clarity
24
  np.set_printoptions(suppress=True)
 
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)
 
47
  gray_img[:,:,1] = gray
48
  gray_img[:,:,2] = gray
49
  return gray_img
50
+ """
51
 
52
  ##Transformation
53
+ def transform_my_model(content_image,style_image):
54
  # Convert to float32 numpy array, add batch dimension, and normalize to range [0, 1]
55
  #content_image=gray_scaled(content_image)
56
+ content_image = content_image.astype(np.float32)[np.newaxis, ...] / 255.
57
+ style_image = style_image.astype(np.float32)[np.newaxis, ...] / 255.
58
 
59
  #Resizing image
60
  #style_image = tf.image.resize(style_image, (256, 256))
 
67
  stylized_image =tensor_to_image(stylized_image)
68
  return stylized_image
69
 
 
 
 
 
 
 
70
 
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=transform_my_model, inputs= [image1,image2] , outputs= stylizedimg,title='Style Transfer',theme='seafoam',examples=[['Content_Images/contnt12.jpg','VG516.jpg']],article="References-\n\nExploring the structure of a real-time, arbitrary neural artistic stylization network. Golnaz Ghiasi, Honglak Lee, Manjunath Kudlur, Vincent Dumoulin.").launch()
75
 
76
 
77