Spaces:
Runtime error
Runtime error
Commit ·
47d1a17
1
Parent(s): 7759242
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,16 +2,20 @@ from huggingface_hub import from_pretrained_keras
|
|
| 2 |
import gradio as gr
|
| 3 |
import tensorflow as tf
|
| 4 |
import numpy as np
|
|
|
|
| 5 |
|
| 6 |
-
model =
|
| 7 |
|
| 8 |
inputs = gr.inputs.Image()
|
| 9 |
output = gr.output.Image()
|
| 10 |
|
| 11 |
|
| 12 |
def predict(image_input):
|
|
|
|
|
|
|
| 13 |
pass
|
| 14 |
-
|
|
|
|
| 15 |
class PreTrainedPipeline():
|
| 16 |
def __init__(self, path: str):
|
| 17 |
# load the model
|
|
@@ -58,7 +62,7 @@ class PreTrainedPipeline():
|
|
| 58 |
binary_masks[f"mask_{cls}"][row][col] = 0
|
| 59 |
|
| 60 |
mask = binary_masks[f"mask_{cls}"]
|
| 61 |
-
mask *= 255
|
| 62 |
img = Image.fromarray(mask.astype(np.int8), mode="L")
|
| 63 |
|
| 64 |
# we need to make it readable for the widget
|
|
@@ -68,4 +72,12 @@ class PreTrainedPipeline():
|
|
| 68 |
mask = base64.b64encode(png_string).decode("utf-8")
|
| 69 |
|
| 70 |
mask_codes[f"mask_{cls}"] = mask
|
|
|
|
| 71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import tensorflow as tf
|
| 4 |
import numpy as np
|
| 5 |
+
import os
|
| 6 |
|
| 7 |
+
model = tf.keras,models.load.model(os.path.join
|
| 8 |
|
| 9 |
inputs = gr.inputs.Image()
|
| 10 |
output = gr.output.Image()
|
| 11 |
|
| 12 |
|
| 13 |
def predict(image_input):
|
| 14 |
+
img = np.array(inputs)
|
| 15 |
+
|
| 16 |
pass
|
| 17 |
+
|
| 18 |
+
|
| 19 |
class PreTrainedPipeline():
|
| 20 |
def __init__(self, path: str):
|
| 21 |
# load the model
|
|
|
|
| 62 |
binary_masks[f"mask_{cls}"][row][col] = 0
|
| 63 |
|
| 64 |
mask = binary_masks[f"mask_{cls}"]
|
| 65 |
+
mask *= 255
|
| 66 |
img = Image.fromarray(mask.astype(np.int8), mode="L")
|
| 67 |
|
| 68 |
# we need to make it readable for the widget
|
|
|
|
| 72 |
mask = base64.b64encode(png_string).decode("utf-8")
|
| 73 |
|
| 74 |
mask_codes[f"mask_{cls}"] = mask
|
| 75 |
+
|
| 76 |
|
| 77 |
+
# widget needs the below format, for each class we return label and mask string
|
| 78 |
+
labels.append({
|
| 79 |
+
"label": f"LABEL_{cls}",
|
| 80 |
+
"mask": mask_codes[f"mask_{cls}"],
|
| 81 |
+
"score": 1.0,
|
| 82 |
+
})
|
| 83 |
+
return labels
|