File size: 1,508 Bytes
263f3ae
 
0b188bd
98f642e
263f3ae
95c2dbb
acc4865
98f642e
f17fbd4
0b188bd
95c2dbb
 
1acad40
95c2dbb
98f642e
939dc58
95c2dbb
185fddd
 
bac12ba
185fddd
546e137
 
bac12ba
 
546e137
bac12ba
 
546e137
 
 
 
 
 
 
 
 
8b52248
546e137
 
a2d9e40
d0c5f8e
98f642e
b26294d
95c2dbb
 
bf44b60
 
 
546e137
0b188bd
98f642e
6589046
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)