File size: 835 Bytes
5ab4572
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3fd1ca0
 
5ab4572
0481f65
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from keras.models import model_from_json
import cv2
import numpy as np

class_names = ['Selfie','Non-Selfie']

f = open("model_cnn1.json",'r+')
json_string = f.read()
f.close()
model = model_from_json(json_string)
model.load_weights('model_cnn1.h5')
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])

def predict_image(img):
  prediction = model.predict(img.reshape(-1,100,100,3))[0]
  return {class_names[i]: float(prediction[i]) for i in range(2)}

import gradio as gr

image = gr.inputs.Image(shape=(100,100),label='Image To Classify')
label = gr.outputs.Label(label='Model thinks your image is')

gr.Interface(fn=predict_image, inputs=image, outputs=label,allow_flagging='never',title="Selfie Detection Web-App",description="Upload an image to check if it is a Selfie or not?").launch(debug='True')