Spaces:
Runtime error
Runtime error
import gradio as gr | |
import tensorflow as tf | |
import keras | |
import numpy as np | |
import sklearn | |
from sklearnex import patch_sklearn, unpatch_sklearn | |
patch_sklearn() | |
import xgboost as xgb | |
xgb_params = { | |
'objective': 'binary:logistic', | |
'predictor': 'cpu_predictor', | |
'disable_default_eval_metric': 'true', | |
} | |
model_xgb= xgb.XGBClassifier(**xgb_params) | |
model_xgb.load_model('xgb.json') | |
base_cnn = keras.applications.resnet50.ResNet50( | |
include_top=True, | |
weights='imagenet', | |
) | |
base_cnn.load_weights('model.keras') | |
def fn(image): | |
if len(image.shape)==2: | |
img = np.stack([image,image,image],axis=2) | |
img = np.resize(img,(224,224,3)) | |
elif len(image.shape)==3 and image.shape[2]==1: | |
img = np.stack([image[:,:,0],image[:,:,0],image[:,:,0]],axis=2) | |
img = np.resize(img,(224,224,3)) | |
else: | |
img = np.resize(image,(224,224,3)) | |
img = np.expand_dims(img,axis=0) | |
feats = base_cnn.predict(img) | |
pred = model_xgb.predict(feats) | |
if pred==0: | |
return 'autism' | |
else: | |
return 'control' | |
demo = gr.Interface( | |
fn,['image'],"text", | |
) | |
if __name__ == "__main__": | |
demo.launch() |