Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -43,10 +43,11 @@ def load_labels() -> list[str]:
|
|
43 |
model = load_model()
|
44 |
labels = load_labels()
|
45 |
|
46 |
-
|
47 |
-
def predict(
|
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()
|
@@ -79,8 +80,7 @@ with gr.Blocks(css="style.css") as demo:
|
|
79 |
with gr.Column():
|
80 |
#image = gr.Image(label="Input", type="pil")
|
81 |
url = gr.Textbox("")
|
82 |
-
|
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():
|
@@ -93,7 +93,7 @@ with gr.Blocks(css="style.css") as demo:
|
|
93 |
result_text = gr.Text(label="Text output", show_label=False, lines=5)
|
94 |
gr.Examples(
|
95 |
examples=examples,
|
96 |
-
inputs=[
|
97 |
outputs=[result, result_json, result_text],
|
98 |
fn=predict,
|
99 |
cache_examples=os.getenv("CACHE_EXAMPLES") == "1",
|
|
|
43 |
model = load_model()
|
44 |
labels = load_labels()
|
45 |
|
46 |
+
#image: PIL.Image.Image
|
47 |
+
def predict(url: str, score_threshold: float) -> tuple[dict[str, float], dict[str, float], str]:
|
48 |
_, height, width, _ = model.input_shape
|
49 |
+
response = requests.get(url)
|
50 |
+
image = PIL.Image.open(BytesIO(response.content))
|
51 |
image = np.asarray(image)
|
52 |
image = tf.image.resize(image, size=(height, width), method=tf.image.ResizeMethod.AREA, preserve_aspect_ratio=True)
|
53 |
image = image.numpy()
|
|
|
80 |
with gr.Column():
|
81 |
#image = gr.Image(label="Input", type="pil")
|
82 |
url = gr.Textbox("")
|
83 |
+
|
|
|
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():
|
|
|
93 |
result_text = gr.Text(label="Text output", show_label=False, lines=5)
|
94 |
gr.Examples(
|
95 |
examples=examples,
|
96 |
+
inputs=[url, score_threshold],
|
97 |
outputs=[result, result_json, result_text],
|
98 |
fn=predict,
|
99 |
cache_examples=os.getenv("CACHE_EXAMPLES") == "1",
|