Update index.html
Browse files- index.html +53 -16
index.html
CHANGED
@@ -1,19 +1,56 @@
|
|
1 |
<!DOCTYPE html>
|
2 |
<html>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
</html>
|
|
|
|
1 |
<!DOCTYPE html>
|
2 |
<html>
|
3 |
+
<head>
|
4 |
+
<script type="module" crossorigin src="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.js"></script>
|
5 |
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.css" />
|
6 |
+
</head>
|
7 |
+
<body>
|
8 |
+
<gradio-lite>
|
9 |
+
|
10 |
+
<gradio-requirements>
|
11 |
+
transformers_js_py
|
12 |
+
</gradio-requirements>
|
13 |
+
|
14 |
+
<gradio-file name="app.py" entrypoint>
|
15 |
+
from transformers_js import import_transformers_js, as_url
|
16 |
+
import gradio as gr
|
17 |
+
|
18 |
+
transformers = await import_transformers_js()
|
19 |
+
pipeline = transformers.pipeline
|
20 |
+
pipe = await pipeline('object-detection', "Xenova/yolos-tiny")
|
21 |
+
|
22 |
+
async def detect(image):
|
23 |
+
result = await pipe(as_url(image))
|
24 |
+
gradio_labels = [
|
25 |
+
# List[Tuple[numpy.ndarray | Tuple[int, int, int, int], str]]
|
26 |
+
(
|
27 |
+
(
|
28 |
+
int(item["box"]["xmin"]),
|
29 |
+
int(item["box"]["ymin"]),
|
30 |
+
int(item["box"]["xmax"]),
|
31 |
+
int(item["box"]["ymax"]),
|
32 |
+
),
|
33 |
+
item["label"],
|
34 |
+
)
|
35 |
+
for item in result
|
36 |
+
]
|
37 |
+
annotated_image_data = image, gradio_labels
|
38 |
+
return annotated_image_data, result
|
39 |
+
|
40 |
+
demo = gr.Interface(
|
41 |
+
detect,
|
42 |
+
gr.Image(type="filepath"),
|
43 |
+
[
|
44 |
+
gr.AnnotatedImage(),
|
45 |
+
gr.JSON(),
|
46 |
+
]
|
47 |
+
)
|
48 |
+
|
49 |
+
demo.launch()
|
50 |
+
</gradio-file>
|
51 |
+
|
52 |
+
</gradio-lite>
|
53 |
+
|
54 |
+
</body>
|
55 |
</html>
|
56 |
+
|