Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,54 +1,29 @@
|
|
1 |
-
import
|
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 |
-
return base64.b64encode(buffered.getvalue()).decode("utf-8")
|
31 |
-
|
32 |
-
def predict(image_str):
|
33 |
-
image = decode_base64(image_str)
|
34 |
-
original_height, original_width, _ = image.shape
|
35 |
-
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
36 |
-
image = cv2.resize(image, (128, 128))
|
37 |
-
image = np.expand_dims(image, axis=0)
|
38 |
-
image = np.expand_dims(image, axis=-1)
|
39 |
-
image = image / 255.0
|
40 |
-
mask = model.predict(image)
|
41 |
-
mask = (mask[0] > 0.5).astype(np.uint8) * 255
|
42 |
-
mask = cv2.resize(mask, (original_width, original_height))
|
43 |
-
return encode_base64(mask)
|
44 |
-
|
45 |
-
iface = gr.Interface(
|
46 |
-
fn=predict,
|
47 |
-
inputs=gr.Textbox(label="Input X-ray Image (base64)"),
|
48 |
-
outputs=gr.Textbox(label="Annotation Mask (base64)"),
|
49 |
-
title="Tooth Segmentation Model",
|
50 |
-
description="Upload a dental X-ray image in base64 format to generate the annotation mask in base64 format.",
|
51 |
-
)
|
52 |
-
|
53 |
-
if __name__ == "__main__":
|
54 |
-
interface.launch()
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from tensorflow.keras.models
|
3 |
+
import load_model
|
4 |
+
import numpy as np
|
5 |
+
import cv2 from huggingface_hub
|
6 |
+
import hf_hub_download
|
7 |
+
|
8 |
+
model_path = hf_hub_download(repo_id="SalmanAboAraj/Tooth1", filename="unet_model.h5")
|
9 |
+
model = load_model(model_path)
|
10 |
+
def predict(image):
|
11 |
+
original_height, original_width, _ = image.shape image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
12 |
+
image = cv2.resize(image, (128, 128))
|
13 |
+
image = np.expand_dims(image, axis=0)
|
14 |
+
image = np.expand_dims(image, axis=-1)
|
15 |
+
image = image / 255.0
|
16 |
+
mask = model.predict(image)
|
17 |
+
mask = (mask[0] > 0.5).astype(np.uint8) * 255
|
18 |
+
mask = cv2.resize(mask, (original_width, original_height))
|
19 |
+
return mask
|
20 |
+
|
21 |
+
iface = gr.Interface(
|
22 |
+
fn=predict,
|
23 |
+
inputs=gr.Image(type="numpy", label="Input X-ray Image"),
|
24 |
+
outputs=gr.Image(type="numpy", label="Annotation Mask"),
|
25 |
+
title="Tooth Segmentation Model",
|
26 |
+
description="Upload a dental X-ray image to generate the annotation mask.", )
|
27 |
+
|
28 |
+
if __name__ == "__main__":
|
29 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|