Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,8 @@ from __future__ import annotations
|
|
5 |
import os
|
6 |
import pathlib
|
7 |
import tarfile
|
8 |
-
|
|
|
9 |
import deepdanbooru as dd
|
10 |
import gradio as gr
|
11 |
import huggingface_hub
|
@@ -41,9 +42,12 @@ def load_labels() -> list[str]:
|
|
41 |
model = load_model()
|
42 |
labels = load_labels()
|
43 |
|
44 |
-
|
45 |
-
def predict(
|
46 |
_, height, width, _ = model.input_shape
|
|
|
|
|
|
|
47 |
image = np.asarray(image)
|
48 |
image = tf.image.resize(image, size=(height, width), method=tf.image.ResizeMethod.AREA, preserve_aspect_ratio=True)
|
49 |
image = image.numpy()
|
@@ -73,7 +77,8 @@ with gr.Blocks(css="style.css") as demo:
|
|
73 |
gr.Markdown(DESCRIPTION)
|
74 |
with gr.Row():
|
75 |
with gr.Column():
|
76 |
-
image = gr.Image(label="Input", type="pil")
|
|
|
77 |
score_threshold = gr.Slider(label="Score threshold", minimum=0, maximum=1, step=0.05, value=0.5)
|
78 |
run_button = gr.Button("Run")
|
79 |
with gr.Column():
|
|
|
5 |
import os
|
6 |
import pathlib
|
7 |
import tarfile
|
8 |
+
import requests
|
9 |
+
from io import BytesIO
|
10 |
import deepdanbooru as dd
|
11 |
import gradio as gr
|
12 |
import huggingface_hub
|
|
|
42 |
model = load_model()
|
43 |
labels = load_labels()
|
44 |
|
45 |
+
#image: PIL.Image.Image
|
46 |
+
def predict(url: str, score_threshold: float) -> tuple[dict[str, float], dict[str, float], str]:
|
47 |
_, height, width, _ = model.input_shape
|
48 |
+
response = requests.get(url)
|
49 |
+
img = Image.open(BytesIO(response.content))
|
50 |
+
|
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()
|
|
|
77 |
gr.Markdown(DESCRIPTION)
|
78 |
with gr.Row():
|
79 |
with gr.Column():
|
80 |
+
#image = gr.Image(label="Input", type="pil")
|
81 |
+
url = gr.Textbox("https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png")
|
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():
|