File size: 916 Bytes
03d60ed
 
693b5b6
03d60ed
 
 
115de17
f2424e1
 
 
 
 
 
 
 
 
 
 
 
03d60ed
f2424e1
03d60ed
 
 
 
 
 
 
 
 
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
import gradio as gr
import tensorflow as tf
model_0 = tf.keras.models.load_model('bestmodel.h5')
def classify_image(inp):
    inp = inp.reshape((-1, 224, 224, 3))
    prediction = model_0.predict(inp)
    if prediction[0][prediction.argmax()]>0.01:
      if prediction.argmax() == 0:
        output = "Rifle violence"
      elif prediction.argmax() == 1:
        output = "guns violence"
      elif prediction.argmax() == 2:
        output = "knife violence"
      elif prediction.argmax() == 3:
        output = "image porno"
      elif prediction.argmax() == 4:
        output = "personne habillée" 
      else:
        output = "tank violence" 
    else:
      output = ""
    return output


image = gr.inputs.Image(shape=(224, 224))
label = gr.outputs.Label(num_top_classes=3)

gr.Interface(
    fn=classify_image, inputs=image, outputs=label, interpretation="default"
).launch()