CoolFace
Apppublic

X-Analysis/teeth-xray-app

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
app.py34 linesDownload Raw Back to root
1import tensorflow as tf2import gradio as gr3from keras.layers import TFSMLayer4import numpy as np5from PIL import Image6 7# Load the TensorFlow SavedModel using Keras 3 syntax8model = TFSMLayer(".", call_endpoint="serving_default")9 10# Preprocessing function11def preprocess_image(image):12    image = image.resize((256, 256))  # Resize to match model input13    image = np.array(image) / 255.0   # Normalize14    image = np.expand_dims(image, axis=0)  # Add batch dimension15    return image.astype(np.float32)16 17# Inference function18def predict(image):19    input_tensor = preprocess_image(image)20    prediction = model(input_tensor)21    prediction = tf.squeeze(prediction, axis=0).numpy()  # Remove batch dim22    mask = (prediction > 0.5).astype(np.uint8) * 255      # Binarize mask23    return Image.fromarray(mask)24 25# Gradio interface26interface = gr.Interface(27    fn=predict,28    inputs=gr.Image(type="pil"),29    outputs=gr.Image(type="pil"),30    title="Teeth Segmentation",31    description="Upload a panoramic X-ray image to segment the teeth using a U-Net model."32)33 34interface.launch()