File size: 1,310 Bytes
8c57cc8
 
 
c20d35d
 
 
 
 
8c57cc8
c20d35d
 
 
8c57cc8
c20d35d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f8ba6e1
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
import platform
import pathlib
import requests
import gradio as gr 
from tensorflow.keras.models import load_model
import numpy as np 
import cv2
from huggingface_hub import hf_hub_download 

# حل مشكلة المسارات في Windows
plt = platform.system()
pathlib.WindowsPath = pathlib.PosixPath

# تحميل النموذج من Hugging Face
model_path = hf_hub_download(repo_id="SalmanAboAraj/Tooth1", filename="unet_model.h5") 
model = load_model(model_path) 

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 باستخدام الإصدار 3.35.2
image = gr.inputs.Image()
iface = gr.Interface(
    fn=predict,
    inputs=image,
    outputs=gr.outputs.Image(type="numpy", label="Annotation Mask"),
    title="Tooth Segmentation Model",
    description="Upload a dental X-ray image to generate the annotation mask."
)

if __name__ == "__main__": 
    iface.launch()