Spaces:
Sleeping
Sleeping
File size: 1,134 Bytes
7689af3 6f3a14d f8ecbb9 6f3a14d 7689af3 0b01d71 c45ab5a bbbaf12 7689af3 f8ecbb9 7689af3 |
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 |
import gradio as gr
import tensorflow as tf
from tensorflow.keras.utils import CustomObjectScope
from tensorflow.keras.layers.experimental.preprocessing import RandomHeight
with CustomObjectScope({'RandomHeight': RandomHeight}):
model_0 = tf.keras.models.load_model('/content/drive/MyDrive/bestmodel_porno_final_meilleure100%2.0.h5')
def classify_image(inp):
inp = inp.reshape((-1, 224, 224, 3))
prediction = model_0.predict(inp)
output = ""
if prediction[0][prediction.argmax()] < 0.84:
output = "bonne image"
elif 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"
return output
image = gr.Image(height=224, width=224)
gr.Interface(
fn=classify_image, inputs=image, outputs="text",live=True, theme="dark-peach",title="API de détection des images violentes",
).launch()
|