File size: 1,101 Bytes
99f4138
 
 
 
 
da4d726
 
99f4138
da4d726
82f467b
99f4138
da4d726
 
 
 
 
 
 
 
 
 
99f4138
da4d726
 
 
 
 
 
 
565e41f
99f4138
565e41f
99f4138
da4d726
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
import gradio as gr
import tensorflow as tf
import numpy as np
from PIL import Image

# Load the saved model
model = tf.keras.models.load_model("saved_model_cnn.keras")

# Define the classes
classes = ['Caries','Gingivitis' ]

# Prediction function
def predict(image):
    image = Image.fromarray(np.uint8(image)).convert("RGB")
    image = image.resize((224, 224))  # Assuming the model expects 224x224 images
    image_array = np.array(image) / 255.0  # Normalize to [0, 1]
    image_array = np.expand_dims(image_array, axis=0)  # Add batch dimension
    prediction = model.predict(image_array)
    predicted_class = classes[np.argmax(prediction)]
    confidence = np.max(prediction)
    return f"Class: {predicted_class}, Confidence: {confidence:.2f}"

# Gradio interface
interface = gr.Interface(
    fn=predict,
    inputs=gr.Image(type="numpy", label="Upload Image"),
    outputs=gr.Textbox(label="Prediction"),
    title="Dental Health Predictor",
    description="Upload an image to predict between Gingivitis and Caries."
)

# Launch the app
if __name__ == "__main__":
    interface.launch()