Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,34 +1,34 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from tensorflow.keras.models import load_model
|
3 |
-
from tensorflow.keras.preprocessing import image
|
4 |
-
import numpy as np
|
5 |
-
from PIL import Image
|
6 |
-
|
7 |
-
|
8 |
-
model = load_model("Model_1.keras")
|
9 |
-
|
10 |
-
|
11 |
-
def predict_image(img):
|
12 |
-
img = img.resize((256, 256))
|
13 |
-
img_array = np.array(img) / 255.0
|
14 |
-
img_array = np.expand_dims(img_array, axis=0)
|
15 |
-
prediction = model.predict(img_array)
|
16 |
-
class_names = ["Fake","Real"]
|
17 |
-
predicted_class = np.argmax(prediction[0])
|
18 |
-
confidence = prediction[0][predicted_class]
|
19 |
-
if confidence < 0.49:
|
20 |
-
return f"C'est une image générée par un Algorithme d'IA, avec une confiance de {confidence*100: .2f}% "
|
21 |
-
elif confidence > 0.52:
|
22 |
-
return f"C'est une image réelle, avec une confiance de {confidence*100:.2f}% "
|
23 |
-
else:
|
24 |
-
return f"Plus ou moins une image rélle, avec une confiance de {confidence*100: .2f}% "
|
25 |
-
|
26 |
-
interface = gr.Interface(
|
27 |
-
fn=predict_image,
|
28 |
-
inputs=gr.Image(type="pil"),
|
29 |
-
outputs="text",
|
30 |
-
title="Détection d'images
|
31 |
-
)
|
32 |
-
|
33 |
-
|
34 |
-
interface.launch("share=True")
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from tensorflow.keras.models import load_model
|
3 |
+
from tensorflow.keras.preprocessing import image
|
4 |
+
import numpy as np
|
5 |
+
from PIL import Image
|
6 |
+
|
7 |
+
|
8 |
+
model = load_model("Model_1.keras")
|
9 |
+
|
10 |
+
|
11 |
+
def predict_image(img):
|
12 |
+
img = img.resize((256, 256))
|
13 |
+
img_array = np.array(img) / 255.0
|
14 |
+
img_array = np.expand_dims(img_array, axis=0)
|
15 |
+
prediction = model.predict(img_array)
|
16 |
+
class_names = ["Fake","Real"]
|
17 |
+
predicted_class = np.argmax(prediction[0])
|
18 |
+
confidence = prediction[0][predicted_class]
|
19 |
+
if confidence < 0.49:
|
20 |
+
return f"C'est une image générée par un Algorithme d'IA, avec une confiance de {confidence*100: .2f}% "
|
21 |
+
elif confidence > 0.52:
|
22 |
+
return f"C'est une image réelle, avec une confiance de {confidence*100:.2f}% "
|
23 |
+
else:
|
24 |
+
return f"Plus ou moins une image rélle, avec une confiance de {confidence*100: .2f}% "
|
25 |
+
|
26 |
+
interface = gr.Interface(
|
27 |
+
fn=predict_image,
|
28 |
+
inputs=gr.Image(type="pil"),
|
29 |
+
outputs="text",
|
30 |
+
title="Détection d'images générées par l'IA"
|
31 |
+
)
|
32 |
+
|
33 |
+
|
34 |
+
interface.launch("share=True")
|