Spaces:
Sleeping
Sleeping
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() |