Update index.html
Browse files- index.html +28 -20
index.html
CHANGED
@@ -20,37 +20,45 @@
|
|
20 |
<body>
|
21 |
<gradio-lite>
|
22 |
<gradio-file name="app.py" entrypoint>
|
|
|
23 |
import gradio as gr
|
24 |
|
25 |
-
|
|
|
|
|
26 |
|
27 |
-
def
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
demo = gr.Interface(
|
32 |
-
|
33 |
-
"
|
34 |
-
|
35 |
-
|
|
|
|
|
36 |
)
|
37 |
|
38 |
demo.launch()
|
39 |
</gradio-file>
|
40 |
|
41 |
-
<gradio-file name="filters.py">
|
42 |
-
from skimage.color import rgb2gray
|
43 |
-
|
44 |
-
def as_gray(image):
|
45 |
-
return rgb2gray(image)
|
46 |
-
</gradio-file>
|
47 |
-
|
48 |
-
<gradio-file name="lion.jpg" url="https://raw.githubusercontent.com/gradio-app/gradio/main/gradio/test_data/lion.jpg" />
|
49 |
-
<gradio-file name="logo.png" url="https://raw.githubusercontent.com/gradio-app/gradio/main/guides/assets/logo.png" />
|
50 |
-
|
51 |
<gradio-requirements>
|
52 |
-
|
53 |
-
scikit-image
|
54 |
</gradio-requirements>
|
55 |
</gradio-lite>
|
56 |
</body>
|
|
|
20 |
<body>
|
21 |
<gradio-lite>
|
22 |
<gradio-file name="app.py" entrypoint>
|
23 |
+
from transformers_js import import_transformers_js, as_url
|
24 |
import gradio as gr
|
25 |
|
26 |
+
transformers = await import_transformers_js()
|
27 |
+
pipeline = transformers.pipeline
|
28 |
+
pipe = await pipeline('object-detection', "Xenova/yolos-tiny")
|
29 |
|
30 |
+
async def detect(input_image):
|
31 |
+
result = await pipe(as_url(input_image))
|
32 |
+
gradio_labels = [
|
33 |
+
# List[Tuple[numpy.ndarray | Tuple[int, int, int, int], str]]
|
34 |
+
(
|
35 |
+
(
|
36 |
+
int(item["box"]["xmin"]),
|
37 |
+
int(item["box"]["ymin"]),
|
38 |
+
int(item["box"]["xmax"]),
|
39 |
+
int(item["box"]["ymax"]),
|
40 |
+
),
|
41 |
+
item["label"],
|
42 |
+
)
|
43 |
+
for item in result
|
44 |
+
]
|
45 |
+
annotated_image_data = input_image, gradio_labels
|
46 |
+
return annotated_image_data, result
|
47 |
|
48 |
demo = gr.Interface(
|
49 |
+
detect,
|
50 |
+
gr.Image(type="filepath"),
|
51 |
+
[
|
52 |
+
gr.AnnotatedImage(),
|
53 |
+
gr.JSON(),
|
54 |
+
]
|
55 |
)
|
56 |
|
57 |
demo.launch()
|
58 |
</gradio-file>
|
59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
<gradio-requirements>
|
61 |
+
transformers_js_py
|
|
|
62 |
</gradio-requirements>
|
63 |
</gradio-lite>
|
64 |
</body>
|