Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
+
from tensorflow.keras.models import load_modelimport gradio as gr
|
3 |
+
import tensorflow as tf
|
4 |
+
import cv2
|
5 |
+
import numpy as np
|
6 |
+
from tensorflow.keras.models import load_model
|
7 |
+
|
8 |
+
# Load the pre-trained model
|
9 |
+
new_model = load_model('imageclassifier.h5')
|
10 |
+
|
11 |
+
def classify_image(img):
|
12 |
+
# Resize the image
|
13 |
+
resize = tf.image.resize(img, (256, 256))
|
14 |
+
|
15 |
+
# Preprocess the image and make prediction
|
16 |
+
yhat = new_model.predict(np.expand_dims(resize / 255, 0))
|
17 |
+
|
18 |
+
# Return the prediction result
|
19 |
+
return "Real" if yhat > 0.5 else "Fake"
|
20 |
+
|
21 |
+
# Create a Gradio interface
|
22 |
+
iface = gr.Interface(
|
23 |
+
fn=classify_image,
|
24 |
+
inputs=gr.Image(),
|
25 |
+
outputs="text",
|
26 |
+
live=True,
|
27 |
+
capture_session=True # Needed for TensorFlow/Keras models
|
28 |
+
)
|
29 |
+
|
30 |
+
# Launch the Gradio interface
|
31 |
+
iface.launch()
|