Update index.html
Browse files- index.html +42 -4
index.html
CHANGED
@@ -22,19 +22,57 @@
|
|
22 |
<gradio-file name="app.py" entrypoint>
|
23 |
import gradio as gr
|
24 |
from transformers_js_py import pipeline
|
|
|
25 |
|
26 |
pipe = await pipeline('object-detection', 'Xenova/detr-resnet-50')
|
27 |
|
28 |
-
|
|
|
|
|
|
|
|
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
demo.launch()
|
31 |
</gradio-file>
|
32 |
|
33 |
<gradio-file name="filters.py">
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
-
def as_gray(image):
|
37 |
-
return rgb2gray(image)
|
38 |
</gradio-file>
|
39 |
|
40 |
<gradio-file name="lion.jpg" url="https://raw.githubusercontent.com/gradio-app/gradio/main/gradio/test_data/lion.jpg" />
|
|
|
22 |
<gradio-file name="app.py" entrypoint>
|
23 |
import gradio as gr
|
24 |
from transformers_js_py import pipeline
|
25 |
+
from filters import convert
|
26 |
|
27 |
pipe = await pipeline('object-detection', 'Xenova/detr-resnet-50')
|
28 |
|
29 |
+
async def fn(image):
|
30 |
+
result = await pipe(image)
|
31 |
+
return result
|
32 |
+
|
33 |
+
#demo = gr.Interface.from_pipeline(pipe)
|
34 |
|
35 |
+
async def predict(image):
|
36 |
+
result = await pipe(image)
|
37 |
+
print(result)
|
38 |
+
result = convert(result)
|
39 |
+
print(result)
|
40 |
+
return image, result
|
41 |
+
|
42 |
+
demo = gr.Interface(
|
43 |
+
fn=predict,
|
44 |
+
inputs=gr.Image(type='pil'),
|
45 |
+
outputs=gr.AnnotatedImage(),
|
46 |
+
)
|
47 |
+
|
48 |
demo.launch()
|
49 |
</gradio-file>
|
50 |
|
51 |
<gradio-file name="filters.py">
|
52 |
+
def convert(input_data):
|
53 |
+
# Initialize the output list
|
54 |
+
result_labels = []
|
55 |
+
|
56 |
+
# Iterate over each item in the input data
|
57 |
+
for item in input_data:
|
58 |
+
# Extract the label
|
59 |
+
label = item['label']
|
60 |
+
|
61 |
+
# Extract the bounding box coordinates
|
62 |
+
xmin = item['box']['xmin']
|
63 |
+
ymin = item['box']['ymin']
|
64 |
+
xmax = item['box']['xmax']
|
65 |
+
ymax = item['box']['ymax']
|
66 |
+
|
67 |
+
# Convert coordinates into the required output format (list of coordinates)
|
68 |
+
coordinates = [xmin, ymin, xmax, ymax]
|
69 |
+
|
70 |
+
# Append the tuple of coordinates and label to the output list
|
71 |
+
result_labels.append((coordinates, label))
|
72 |
+
|
73 |
+
# Return the output list
|
74 |
+
return result_labels
|
75 |
|
|
|
|
|
76 |
</gradio-file>
|
77 |
|
78 |
<gradio-file name="lion.jpg" url="https://raw.githubusercontent.com/gradio-app/gradio/main/gradio/test_data/lion.jpg" />
|