Spaces:
Running
Running
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() |