Spaces:
Runtime error
Runtime error
siriuszeina
commited on
Commit
•
9b3c5fd
1
Parent(s):
9e510f6
Update app.py
Browse files
app.py
CHANGED
@@ -43,12 +43,10 @@ def load_labels() -> list[str]:
|
|
43 |
model = load_model()
|
44 |
labels = load_labels()
|
45 |
|
46 |
-
#PIL.Image.Image
|
47 |
-
def predict(image: str, score_threshold: float) -> tuple[dict[str, float], dict[str, float], str]:
|
48 |
-
_, height, width, _ = model.input_shape
|
49 |
-
response = requests.get(image)
|
50 |
-
image = Image.open(BytesIO(response.content))
|
51 |
|
|
|
|
|
|
|
52 |
image = np.asarray(image)
|
53 |
image = tf.image.resize(image, size=(height, width), method=tf.image.ResizeMethod.AREA, preserve_aspect_ratio=True)
|
54 |
image = image.numpy()
|
@@ -76,9 +74,13 @@ examples = [[path.as_posix(), 0.5] for path in image_paths]
|
|
76 |
|
77 |
with gr.Blocks(css="style.css") as demo:
|
78 |
gr.Markdown(DESCRIPTION)
|
|
|
79 |
with gr.Row():
|
80 |
with gr.Column():
|
81 |
-
image = gr.Image(label="Input", type="pil")
|
|
|
|
|
|
|
82 |
score_threshold = gr.Slider(label="Score threshold", minimum=0, maximum=1, step=0.05, value=0.5)
|
83 |
run_button = gr.Button("Run")
|
84 |
with gr.Column():
|
@@ -99,7 +101,7 @@ with gr.Blocks(css="style.css") as demo:
|
|
99 |
|
100 |
run_button.click(
|
101 |
fn=predict,
|
102 |
-
inputs=[
|
103 |
outputs=[result, result_json, result_text],
|
104 |
api_name="predict",
|
105 |
)
|
|
|
43 |
model = load_model()
|
44 |
labels = load_labels()
|
45 |
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
+
def predict(image: PIL.Image.Image, score_threshold: float) -> tuple[dict[str, float], dict[str, float], str]:
|
48 |
+
_, height, width, _ = model.input_shape
|
49 |
+
|
50 |
image = np.asarray(image)
|
51 |
image = tf.image.resize(image, size=(height, width), method=tf.image.ResizeMethod.AREA, preserve_aspect_ratio=True)
|
52 |
image = image.numpy()
|
|
|
74 |
|
75 |
with gr.Blocks(css="style.css") as demo:
|
76 |
gr.Markdown(DESCRIPTION)
|
77 |
+
|
78 |
with gr.Row():
|
79 |
with gr.Column():
|
80 |
+
#image = gr.Image(label="Input", type="pil")
|
81 |
+
url = gr.Textbox("")
|
82 |
+
response = requests.get(url)
|
83 |
+
image = PIL.Image.open(BytesIO(response.content))
|
84 |
score_threshold = gr.Slider(label="Score threshold", minimum=0, maximum=1, step=0.05, value=0.5)
|
85 |
run_button = gr.Button("Run")
|
86 |
with gr.Column():
|
|
|
101 |
|
102 |
run_button.click(
|
103 |
fn=predict,
|
104 |
+
inputs=[url, score_threshold],
|
105 |
outputs=[result, result_json, result_text],
|
106 |
api_name="predict",
|
107 |
)
|