File size: 1,325 Bytes
919da6e
223671b
96eb944
 
 
919da6e
96eb944
223671b
 
 
 
 
 
 
96eb944
 
4a02bf5
96eb944
 
 
223671b
96eb944
 
 
 
 
 
 
 
b86c944
36e14c6
96eb944
 
 
 
 
 
36e14c6
 
9cde633
b2558f7
 
96eb944
03e7e0a
919da6e
8248152
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import gradio as gr
import numpy as np
import tensorflow as tf
import PIL
import os

'''
def sepia(input_img):
  sepia_filter = np.array([[.393, .769, .189],
                           [.349, .686, .168],
                           [.272, .534, .131]])
  sepia_img = input_img.dot(sepia_filter.T)
  sepia_img /= sepia_img.max()                          
  return sepia_img
 '''
 
def normalize_img(img):
    img = tf.cast(img, dtype=tf.float32)
    # Map values in the range [-1, 1]
    return (img / 127.5) - 1.0

def predict_and_save(img, generator_model):
    img = normalize_img(img)
    prediction = generator_model(img, training=False)[0].numpy() 
    prediction = (prediction * 127.5 + 127.5).astype(np.uint8)  
    im = PIL.Image.fromarray(prediction)
    return im
    
def run(image_path):
    model = tf.keras.models.load_model('pretrained')  
    '''
    img = tf.keras.preprocessing.image.load_img(
        image_path, target_size=(256, 256)
    )
    
    img_array = tf.keras.preprocessing.image.img_to_array(img)
    img_array = tf.expand_dims(img_array, 0) 
    '''
    #predict_and_save(img_array, model)
    img_array = tf.expand_dims(image_path, 0)
    im = predict_and_save(img_array, model)
    return im

iface = gr.Interface(run, gr.inputs.Image(shape=(256, 256)), "image")

iface.launch(share = True)