File size: 1,308 Bytes
0b188bd
 
98f642e
59638ad
 
5bbc116
98f642e
0b188bd
 
 
98f642e
 
0b188bd
98f642e
0b188bd
 
 
 
 
 
 
98f642e
 
 
0b188bd
 
 
 
 
 
 
98f642e
0b188bd
98f642e
f9351da
98f642e
0b188bd
98f642e
0b188bd
98f642e
59638ad
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
import json
import numpy as np
import gradio as gr
import tensorflow as tf
from PIL import Image
from tensorflow.keras.models import load_model
# Load the model
model_path = 'final_teath_classifier.h5'
model = tf.keras.models.load_model(model_path)

# Define preprocessing function
def preprocess_image(image):
    # Resize the image to match input size
    image = Image.fromarray(image)
    image = image.resize((256, 256))
    # Convert image to array and preprocess input
    img_array = np.array(image) / 255.0
    # Add batch dimension
    img_array = np.expand_dims(img_array, axis=0)
    return img_array

# Define prediction function
def predict_image(image):
    img_array = preprocess_image(image)
    outputs = model(img_array)
    predictions = tf.nn.softmax(outputs.logits, axis=-1)
    predicted_class = np.argmax(predictions)
    if predicted_class == 0:
        predict_label = "Clean"
    else:
        predict_label = "Carries"
    return {"prediction": predict_label, "confidence": float(np.max(predictions))}

# Create the interface
input_interface = gr.inputs.Image(shape=(256, 256), image_mode='RGB')
output_interface = gr.outputs.Label(num_top_classes=2)

iface = gr.Interface(fn=predict_image, inputs=input_interface, outputs=output_interface)

# Launch the interface
iface.launch()