File size: 1,065 Bytes
3b6f551
 
 
 
 
587269e
3b6f551
 
 
587269e
3b6f551
 
587269e
3b6f551
 
587269e
 
3b6f551
 
587269e
3b6f551
 
 
 
587269e
3b6f551
 
 
 
 
 
 
587269e
3b6f551
 
 
 
 
587269e
3b6f551
 
 
cfabb85
3b6f551
 
 
 
cfabb85
 
 
3b6f551
 
587269e
 
cfabb85
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import gradio as gr
import tensorflow as tf
import numpy as np
from PIL import Image


model = tf.keras.models.load_model('meu_modelo.h5')

def predict_image(img):
    
    img = np.array(img)

    
    img = tf.image.resize(img, (224, 224))

    # MobileNetV2:
    
    img = img / 127.5 - 1

    
    img = np.expand_dims(img, axis=0)

    prediction = model.predict(img)

    
    if prediction < 0.5:
        result = {"ai": float(1 - prediction[0][0]), "human": float(prediction[0][0])}
    else:
        result = {"human": float(prediction[0][0]), "ai": float(1 - prediction[0][0])}

    return result


exemplos = [
    'vangoghai.jpg',
    'vangoghhuman.jpg'
]

#gradio
image_input = gr.Image()
label_output = gr.Label()

# Gradio Interface
interface = gr.Interface(
    fn=predict_image,
    inputs=image_input,
    outputs=label_output,
    examples=exemplos,
    title="Image-Classifier-AIvsHuman",
    description="Upload an image and the output will tell you whether it's potentially AI-generated or human-generated."
)

interface.launch(debug=True)