Spaces:
Sleeping
Sleeping
import os | |
import pandas as pd | |
import keras | |
### This is to predict gender | |
def main_fn(Name_): | |
##Input structure into model is## | |
filename = "training_2/gender_v1_freezebert.h5" | |
if os.path.exists(filename): | |
model = tf.keras.models.load_model((filename), custom_objects={'KerasLayer':hub.KerasLayer}) | |
print('loaded model') | |
else: | |
print('failed loading model') | |
prob = model.predict([Name_]) | |
female_prob = prob[0][0] | |
if female_prob>0.5: | |
gender = 'female' | |
prob = female_prob | |
else: | |
gender = 'male' | |
prob = (1-female_prob) | |
return gender, prob | |
if __name__ == "__main__": | |
Name_ = 'John' | |
gender, female_prob = main_fn(Name_) | |
print(gender) | |