File size: 1,508 Bytes
263f3ae
 
0b188bd
98f642e
263f3ae
d101830
acc4865
98f642e
f17fbd4
0b188bd
95c2dbb
d101830
 
 
98f642e
939dc58
d101830
 
 
 
 
dc5b033
33c9fd1
bac12ba
 
d101830
 
bac12ba
d101830
 
 
dc5b033
d101830
dc5b033
 
d101830
dc5b033
8b52248
b26294d
d101830
 
d0c5f8e
98f642e
b26294d
d101830
 
bf44b60
 
 
d101830
0b188bd
98f642e
d101830
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
from PIL import Image
import tensorflow as tf
import numpy as np
import gradio as gr
import io
import json

# Load the model
model_path = 'final_teath_classifier.h5'
model = tf.keras.models.load_model(model_path)

# Define preprocessing function


# Define prediction function
def predict_image(image):
    # Save the image to a file-like object
    image_bytes = io.BytesIO()
    image.save(image_bytes, format="JPEG")

    # Load the image from the file-like object
    image = tf.keras.preprocessing.image.load_img(image_bytes, target_size=(256, 256,3))
    image = np.array(image)/255
    image = np.expand_dims(image, axis=0)

    # Make a prediction
    prediction = model.predict(image)

    # Get the probability of being 'Clean' or 'Carries'
    probabilities = tf.nn.softmax(prediction, axis=-1)
    predicted_class_index = np.argmax(probabilities)
    if predicted_class_index == 1:
        predicted_label = "Clean"
        predicted_probability = probabilities[0][1] * 100  # Convert to percentage
    elif predicted_class_index == 0:
        predicted_label = "Carries"
        predicted_probability = probabilities[0][0] * 100  # Convert to percentage

    # Return the prediction result as a dictionary
    return {"Predicted Label": predicted_label}


# Create the interface
input_interface = gr.Image(type="pil")
output_interface = "json"

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

# Launch the interface
iface.launch(share=True)