lunalade commited on
Commit
04aca4b
·
verified ·
1 Parent(s): b18d98b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -1,19 +1,25 @@
1
- import gradio as gr
 
 
 
2
  import tensorflow as tf
 
3
  import cv2
4
  import numpy as np
 
 
 
5
  from skimage import feature
6
 
7
  # Model path...
8
- edges2ferrets = './e299999_generator.h5'
9
 
10
- # Load the Pix2Pix generator model
11
  ferretMaker = tf.keras.models.load_model(edges2ferrets)
12
 
13
  def transform_image(img, input_type):
14
- sigma = 1.7 # Placeholder value for sigma
15
  if input_type == "Photo":
16
- # Resize the input photo to 256x256
17
  img = cv2.resize(img, (256, 256))
18
 
19
  # Convert the input photo to grayscale
@@ -24,7 +30,7 @@ def transform_image(img, input_type):
24
  processed_input = cv2.cvtColor(edges, cv2.COLOR_GRAY2RGB)
25
 
26
  elif input_type == "Drawing":
27
- # Resize the input drawing to 256x256
28
  img = cv2.resize(img, (256, 256))
29
 
30
  # Applies CV2 transformation to input drawing
@@ -40,6 +46,7 @@ def transform_image(img, input_type):
40
 
41
  return generated_ferret.astype(np.uint8)
42
 
 
43
  iface = gr.Interface(
44
  fn=transform_image,
45
  inputs=[gr.Image(type="numpy", image_mode="RGB"), gr.Radio(["Photo", "Drawing"], label="Select Input Type")],
 
1
+ # Installs
2
+ !pip install gradio
3
+
4
+ # Imports
5
  import tensorflow as tf
6
+ import gradio as gr
7
  import cv2
8
  import numpy as np
9
+ from PIL import Image
10
+ import sys
11
+ import os
12
  from skimage import feature
13
 
14
  # Model path...
15
+ edges2ferrets = './FINAL_EDGES2FERRETS.hd5'
16
 
 
17
  ferretMaker = tf.keras.models.load_model(edges2ferrets)
18
 
19
  def transform_image(img, input_type):
20
+ sigma = 1.7
21
  if input_type == "Photo":
22
+ # Resize the input
23
  img = cv2.resize(img, (256, 256))
24
 
25
  # Convert the input photo to grayscale
 
30
  processed_input = cv2.cvtColor(edges, cv2.COLOR_GRAY2RGB)
31
 
32
  elif input_type == "Drawing":
33
+ # Resize the input
34
  img = cv2.resize(img, (256, 256))
35
 
36
  # Applies CV2 transformation to input drawing
 
46
 
47
  return generated_ferret.astype(np.uint8)
48
 
49
+ # Different canny logic is applied depending on the input the user selects. With photo, skimage is applied, and with drawing cv2 bw is applied.
50
  iface = gr.Interface(
51
  fn=transform_image,
52
  inputs=[gr.Image(type="numpy", image_mode="RGB"), gr.Radio(["Photo", "Drawing"], label="Select Input Type")],