Spaces:
Sleeping
Sleeping
File size: 1,597 Bytes
1569d2f 7dad634 ba98396 7dad634 b87fe24 7dad634 20708ad 7dad634 66080ac 7dad634 |
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 36 37 38 39 |
import gradio as gr
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.preprocessing import image
import numpy as np
import io
import os
from PIL import Image
def main(img):
model = keras.models.load_model('./ai_real_classifier.h5')
# Save the uploaded image to a temporary file
img_path = 'temp_image.jpg'
Image.fromarray(img).save(img_path)
img = image.load_img(img_path, target_size=(150, 150, 3))
img_array = image.img_to_array(img)
img_array = np.expand_dims(img_array, axis=0)
img_array /= 255.0
# Make predictions
predictions = model.predict(img_array)
confidence = 0.001
# Interpret the predictions
if predictions[0][0] > confidence:
class_label = 'real'
else:
class_label = 'AI Generated'
# Clean up the temporary image file
os.remove(img_path)
return "The image is classified as " + str(class_label) + " \n\n | Please note that this model is only a demonstration of how the A.I.R.S architecture works, we are working on better and more accurate models. If you would like to support us through a donation, you can visit freecs.org/donate"
demo = gr.Interface(fn=main, inputs="image", outputs="text", title="Artificial Image Recognition System", description="This model recognize whether an image is real or AI-generated. With the A.I.R.S architecture we aim to solve all the Deep Fake related problems. If you would like to support us through a donation, you can visit [freecs.org/donate](http://freecs.org/donate). Created by [gr](http://gr.freecs.org) ")
demo.launch() |