akhaliq HF staff commited on
Commit
b5cd2b2
·
1 Parent(s): 839b81b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -10,6 +10,15 @@ import gradio as gr
10
  # Declaring Constants
11
  SAVED_MODEL_PATH = "https://tfhub.dev/captain-pool/esrgan-tf2/1"
12
 
 
 
 
 
 
 
 
 
 
13
  def preprocess_image(image_path):
14
  """ Loads image from path and preprocesses to make it model ready
15
  Args:
@@ -40,11 +49,12 @@ def plot_image(image):
40
 
41
  model = hub.load(SAVED_MODEL_PATH)
42
  def inference(img):
43
- hr_image = preprocess_image(img)
 
44
  fake_image = model(hr_image)
45
  fake_image = tf.squeeze(fake_image)
46
  pil_image = plot_image(tf.squeeze(fake_image))
47
  return pil_image
48
 
49
- gr.Interface(inference,gr.inputs.Image(type="filepath",shape=(256,256)),"image").launch(enable_queue=True)
50
 
 
10
  # Declaring Constants
11
  SAVED_MODEL_PATH = "https://tfhub.dev/captain-pool/esrgan-tf2/1"
12
 
13
+ def resize(width,img):
14
+ basewidth = width
15
+ img = Image.open(img)
16
+ wpercent = (basewidth/float(img.size[0]))
17
+ hsize = int((float(img.size[1])*float(wpercent)))
18
+ img = img.resize((basewidth,hsize), Image.ANTIALIAS)
19
+ img.save('somepic.jpg')
20
+ return 'somepic.jpg'
21
+
22
  def preprocess_image(image_path):
23
  """ Loads image from path and preprocesses to make it model ready
24
  Args:
 
49
 
50
  model = hub.load(SAVED_MODEL_PATH)
51
  def inference(img):
52
+ resize_image = resize(256,img)
53
+ hr_image = preprocess_image(resize_image)
54
  fake_image = model(hr_image)
55
  fake_image = tf.squeeze(fake_image)
56
  pil_image = plot_image(tf.squeeze(fake_image))
57
  return pil_image
58
 
59
+ gr.Interface(inference,gr.inputs.Image(type="filepath"),"image").launch(enable_queue=True)
60