File size: 1,387 Bytes
5d2e65e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3ab8725
 
decf0a9
3ab8725
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
try:
    import tensorflow as tf
    print("TensorFlow version:", tf.__version__)
except ImportError:
    print("TensorFlow is not installed. Installing now...")
    try:
        import pip
        pip.main(['install', 'tensorflow'])
    except AttributeError:
        import subprocess
        subprocess.call(['pip', 'install', 'tensorflow'])

    # Now try importing again
    try:
        import tensorflow as tf
        print("TensorFlow has been successfully installed. Version:", tf.__version__)
    except ImportError:
        print("Installation failed. Please install TensorFlow manually.")
import gradio as gr
import numpy as np
from tensorflow.keras.models import load_model

loaded_model = load_model("gender_classifier_model.h5")


def myfun(img):
    # Gradio automatically converts the input image to a NumPy array
    # Convert the image to the required input format for the model
    img = tf.image.resize(img, (64, 64))
    x = tf.keras.preprocessing.image.img_to_array(img)
    x = np.expand_dims(x, axis=0)

    # Use the loaded model for predictions
    loaded_classes = loaded_model.predict(x, batch_size=1)
    print(loaded_classes)
    if loaded_classes[0] > 0.5:
        return 'Is a Man'
    else:
        return 'Is A Woman'


iface = gr.Interface(fn=myfun, inputs=gr.Image(label='Drop an Image or Open Camera to Classify'), outputs=gr.Text())
iface.launch()