Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import platform
|
2 |
+
import pathlib
|
3 |
+
import requests
|
4 |
+
import gradio as gr
|
5 |
+
from tensorflow.keras.models import load_model
|
6 |
+
import numpy as np
|
7 |
+
import cv2
|
8 |
+
from huggingface_hub import hf_hub_download
|
9 |
+
|
10 |
+
# حل مشكلة المسارات في Windows
|
11 |
+
plt = platform.system()
|
12 |
+
pathlib.WindowsPath = pathlib.PosixPath
|
13 |
+
|
14 |
+
# تحميل النموذج من Hugging Face
|
15 |
+
model_path = hf_hub_download(repo_id="SalmanAboAraj/Tooth1", filename="unet_model.h5")
|
16 |
+
model = load_model(model_path)
|
17 |
+
|
18 |
+
def predict(image):
|
19 |
+
original_height, original_width, _ = image.shape
|
20 |
+
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
21 |
+
image = cv2.resize(image, (128, 128))
|
22 |
+
image = np.expand_dims(image, axis=0)
|
23 |
+
image = np.expand_dims(image, axis=-1)
|
24 |
+
image = image / 255.0
|
25 |
+
mask = model.predict(image)
|
26 |
+
mask = (mask[0] > 0.5).astype(np.uint8) * 255
|
27 |
+
mask = cv2.resize(mask, (original_width, original_height))
|
28 |
+
return mask
|
29 |
+
|
30 |
+
# إنشاء واجهة Gradio باستخدام الإصدار 3.35.2
|
31 |
+
image = gr.inputs.Image()
|
32 |
+
iface = gr.Interface(
|
33 |
+
fn=predict,
|
34 |
+
inputs=image,
|
35 |
+
outputs=gr.outputs.Image(type="numpy", label="Annotation Mask"),
|
36 |
+
title="Tooth Segmentation Model",
|
37 |
+
description="Upload a dental X-ray image to generate the annotation mask."
|
38 |
+
)
|
39 |
+
|
40 |
+
if __name__ == "__main__":
|
41 |
+
iface.launch(inline=False)
|