Spaces:
Running
Running
MuGeminorum
commited on
Commit
•
4abe101
1
Parent(s):
1c7433a
fix app py
Browse files- .gitignore +1 -0
- app.py +41 -0
.gitignore
CHANGED
@@ -3,3 +3,4 @@ _local/
|
|
3 |
*.pyc
|
4 |
local_models_*/
|
5 |
rename.sh
|
|
|
|
3 |
*.pyc
|
4 |
local_models_*/
|
5 |
rename.sh
|
6 |
+
*.onnx
|
app.py
CHANGED
@@ -1,12 +1,43 @@
|
|
|
|
1 |
import cv2
|
2 |
import khandy
|
|
|
3 |
import numpy as np
|
4 |
import gradio as gr
|
|
|
5 |
from PIL import Image
|
6 |
from insectid import InsectDetector
|
7 |
from insectid import InsectIdentifier
|
8 |
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
def inference(filename):
|
11 |
detector = InsectDetector()
|
12 |
identifier = InsectIdentifier()
|
@@ -66,6 +97,16 @@ def inference(filename):
|
|
66 |
return Image.fromarray(image_for_draw[:, :, ::-1], mode='RGB')
|
67 |
|
68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
with gr.Blocks() as demo:
|
70 |
with gr.Tab("Image"):
|
71 |
gr.Markdown("## Insect Inference on Image")
|
|
|
1 |
+
import os
|
2 |
import cv2
|
3 |
import khandy
|
4 |
+
import requests
|
5 |
import numpy as np
|
6 |
import gradio as gr
|
7 |
+
from tqdm import tqdm
|
8 |
from PIL import Image
|
9 |
from insectid import InsectDetector
|
10 |
from insectid import InsectIdentifier
|
11 |
|
12 |
|
13 |
+
def download_model(url, local_path):
|
14 |
+
# Check if the file exists
|
15 |
+
if not os.path.exists(local_path):
|
16 |
+
print(f"Downloading file from {url}...")
|
17 |
+
# Make a request to the URL
|
18 |
+
response = requests.get(url, stream=True)
|
19 |
+
|
20 |
+
# Get the total file size in bytes
|
21 |
+
total_size = int(response.headers.get('content-length', 0))
|
22 |
+
|
23 |
+
# Initialize the tqdm progress bar
|
24 |
+
progress_bar = tqdm(total=total_size, unit='B', unit_scale=True)
|
25 |
+
|
26 |
+
# Open a local file with write-binary mode
|
27 |
+
with open(local_path, 'wb') as file:
|
28 |
+
for data in response.iter_content(chunk_size=1024):
|
29 |
+
# Update the progress bar
|
30 |
+
progress_bar.update(len(data))
|
31 |
+
|
32 |
+
# Write the data to the local file
|
33 |
+
file.write(data)
|
34 |
+
|
35 |
+
# Close the progress bar
|
36 |
+
progress_bar.close()
|
37 |
+
|
38 |
+
print("Download completed.")
|
39 |
+
|
40 |
+
|
41 |
def inference(filename):
|
42 |
detector = InsectDetector()
|
43 |
identifier = InsectIdentifier()
|
|
|
97 |
return Image.fromarray(image_for_draw[:, :, ::-1], mode='RGB')
|
98 |
|
99 |
|
100 |
+
domain = "https://huggingface.co/MuGeminorum/insecta/resolve/main/"
|
101 |
+
download_model(
|
102 |
+
f"{domain}quarrying_insect_detector.onnx",
|
103 |
+
"./insectid/models/quarrying_insect_detector.onnx"
|
104 |
+
)
|
105 |
+
download_model(
|
106 |
+
f"{domain}quarrying_insect_identifier.onnx",
|
107 |
+
"./insectid/models/quarrying_insect_identifier.onnx"
|
108 |
+
)
|
109 |
+
|
110 |
with gr.Blocks() as demo:
|
111 |
with gr.Tab("Image"):
|
112 |
gr.Markdown("## Insect Inference on Image")
|