|
import gradio as gr |
|
import tensorflow as tf |
|
import numpy as np |
|
from PIL import Image |
|
|
|
|
|
model = tf.keras.models.load_model("saved_model_cnn.keras") |
|
|
|
|
|
classes = ['Caries','Gingivitis' ] |
|
|
|
|
|
def predict(image): |
|
image = Image.fromarray(np.uint8(image)).convert("RGB") |
|
image = image.resize((224, 224)) |
|
image_array = np.array(image) / 255.0 |
|
image_array = np.expand_dims(image_array, axis=0) |
|
prediction = model.predict(image_array) |
|
predicted_class = classes[np.argmax(prediction)] |
|
confidence = np.max(prediction) |
|
return f"Class: {predicted_class}, Confidence: {confidence:.2f}" |
|
|
|
|
|
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." |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
interface.launch() |
|
|