File size: 946 Bytes
4671bd2
 
 
 
 
 
 
 
 
25153d5
4671bd2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import numpy as np
from tensorflow.keras.models import load_model
from keras.applications.imagenet_utils import preprocess_input
from tensorflow.keras.preprocessing import image
import requests
from PIL import Image
import io

model = load_model('vgg_model.h5')

def infer(image_url):
    # Load and preprocess the image
    response = requests.get(image_url)
    image = Image.open(io.BytesIO(response.content))
    image = image.resize((224, 224))  # Resize image to match input size of VGG16
    x = image
    x = np.expand_dims(x, axis=0)
    x = preprocess_input(x)
    
    # Perform inference
    preds = model.predict(x)
    result = preds[0][0]

    # Determine the label
    if result < preds[0][1]:
        label = "messy"
    else:
        label = "clean"
        
    return label

# Create a Gradio interface
iface = gr.Interface(fn=infer, inputs="text", outputs="text", title="Image Classifier")
iface.launch()