Spaces:
Running
Running
admin
commited on
Commit
·
c1688c1
1
Parent(s):
cea65bf
2 en
Browse files
app.py
CHANGED
@@ -7,13 +7,14 @@ from modelscope import snapshot_download
|
|
7 |
from insectid import InsectDetector, InsectIdentifier
|
8 |
|
9 |
MODEL_DIR = snapshot_download(
|
10 |
-
"Genius-Society/insecta",
|
|
|
11 |
)
|
12 |
|
13 |
|
14 |
def infer(filename: str):
|
15 |
if not filename:
|
16 |
-
None, "
|
17 |
|
18 |
detector = InsectDetector()
|
19 |
identifier = InsectIdentifier()
|
@@ -27,7 +28,7 @@ def infer(filename: str):
|
|
27 |
image_for_draw = image.copy()
|
28 |
image_height, image_width = image.shape[:2]
|
29 |
boxes, confs, classes = detector.detect(image)
|
30 |
-
text = "
|
31 |
for box, _, _ in zip(boxes, confs, classes):
|
32 |
box = box.astype(np.int32)
|
33 |
box_width = box[2] - box[0] + 1
|
@@ -40,8 +41,7 @@ def infer(filename: str):
|
|
40 |
print(results[0])
|
41 |
prob = results[0]["probability"]
|
42 |
if prob >= 0.10:
|
43 |
-
text = "{}
|
44 |
-
results[0]["chinese_name"],
|
45 |
results[0]["latin_name"],
|
46 |
100.0 * results[0]["probability"],
|
47 |
)
|
@@ -72,14 +72,12 @@ if __name__ == "__main__":
|
|
72 |
with gr.Blocks() as demo:
|
73 |
gr.Interface(
|
74 |
fn=infer,
|
75 |
-
inputs=gr.Image(
|
76 |
-
label="上传昆虫照片 Upload insect picture", type="filepath"
|
77 |
-
),
|
78 |
outputs=[
|
79 |
-
gr.Image(label="
|
80 |
-
gr.Textbox(label="
|
81 |
],
|
82 |
-
title="
|
83 |
examples=[
|
84 |
f"{MODEL_DIR}/examples/butterfly.jpg",
|
85 |
f"{MODEL_DIR}/examples/beetle.jpg",
|
|
|
7 |
from insectid import InsectDetector, InsectIdentifier
|
8 |
|
9 |
MODEL_DIR = snapshot_download(
|
10 |
+
"Genius-Society/insecta",
|
11 |
+
cache_dir="./insectid/__pycache__",
|
12 |
)
|
13 |
|
14 |
|
15 |
def infer(filename: str):
|
16 |
if not filename:
|
17 |
+
None, "Please upload a picture"
|
18 |
|
19 |
detector = InsectDetector()
|
20 |
identifier = InsectIdentifier()
|
|
|
28 |
image_for_draw = image.copy()
|
29 |
image_height, image_width = image.shape[:2]
|
30 |
boxes, confs, classes = detector.detect(image)
|
31 |
+
text = "Unknown"
|
32 |
for box, _, _ in zip(boxes, confs, classes):
|
33 |
box = box.astype(np.int32)
|
34 |
box_width = box[2] - box[0] + 1
|
|
|
41 |
print(results[0])
|
42 |
prob = results[0]["probability"]
|
43 |
if prob >= 0.10:
|
44 |
+
text = "{}: {:.2f}%".format(
|
|
|
45 |
results[0]["latin_name"],
|
46 |
100.0 * results[0]["probability"],
|
47 |
)
|
|
|
72 |
with gr.Blocks() as demo:
|
73 |
gr.Interface(
|
74 |
fn=infer,
|
75 |
+
inputs=gr.Image(label="Upload insect picture", type="filepath"),
|
|
|
|
|
76 |
outputs=[
|
77 |
+
gr.Image(label="Recognition result"),
|
78 |
+
gr.Textbox(label="Best match", show_copy_button=True),
|
79 |
],
|
80 |
+
title="Image file format support PNG, JPG, JPEG and BMP, and the file size does not exceed 10M.",
|
81 |
examples=[
|
82 |
f"{MODEL_DIR}/examples/butterfly.jpg",
|
83 |
f"{MODEL_DIR}/examples/beetle.jpg",
|