File size: 1,365 Bytes
af73ac1
dfd0c07
af73ac1
7a2ccad
af73ac1
b508a71
af73ac1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b508a71
af73ac1
 
b508a71
af73ac1
 
c6c0cac
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
import gradio as gr
from tensorflow.keras.models import load_model
import numpy as np
import cv2
from huggingface_hub import hf_hub_download

# Load the model
model_path = hf_hub_download(repo_id="SalmanAboAraj/Tooth1", filename="unet_model.h5")
model = load_model(model_path)

# Define prediction function
def predict(image):
    original_height, original_width, _ = image.shape
    image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    image = cv2.resize(image, (128, 128))
    image = np.expand_dims(image, axis=0)
    image = np.expand_dims(image, axis=-1)
    image = image / 255.0
    mask = model.predict(image)
    mask = (mask[0] > 0.5).astype(np.uint8) * 255
    mask = cv2.resize(mask, (original_width, original_height))
    return mask

# Gradio Blocks interface
with gr.Blocks() as demo:
    with gr.Row():
        with gr.Column():
            image_input = gr.Image(type="numpy", label="Input X-ray Image")
            mask_output = gr.Image(type="numpy", label="Annotation Mask")
        with gr.Column():
            gr.Markdown("# Tooth Segmentation Model")
            gr.Markdown("Upload a dental X-ray image to generate the annotation mask.")
    
    # Linking inputs and outputs with the prediction function
    image_input.change(predict, inputs=image_input, outputs=mask_output)

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