farid678 commited on
Commit
5056ec5
1 Parent(s): 3b1e236

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import keras
3
+ import tensorflow
4
+ from keras.models import model_from_json
5
+ import numpy as np
6
+
7
+
8
+ def predict_age_gender(image):
9
+ json_file = open('final_mobilenet.json', 'r')
10
+ loaded_file_json = json_file.read()
11
+ json_file.close()
12
+
13
+ model = model_from_json(loaded_file_json)
14
+ model.load_weights('final_mobilenet.h5')
15
+
16
+
17
+ # img_pixels = image.img_to_array(image)
18
+ # img = tf.reshape(image, shape=(-1, 128, 128, 3))
19
+ img_pixels = np.expand_dims(image, axis=0)
20
+ img_pixels = image.astype('float')
21
+ img_pixels = img_pixels.reshape((1, 128, 128, 3))
22
+ img_pixels /= 255
23
+
24
+ predict = model.predict(img_pixels)
25
+ gender_predict = predict[0]
26
+ age_predict = predict[1]
27
+ return {'Gender': ['Fmale' if gender_predict > 0.5 else 'Male'], 'Age': age_predict[0][0]}
28
+
29
+
30
+ iface = gr.Interface(predict_age_gender, gr.Image(), gr.Text())
31
+ iface.launch(share=True)