Spaces:
Runtime error
Runtime error
File size: 1,163 Bytes
7e93763 |
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 47 48 49 |
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() |