Spaces:
Sleeping
Sleeping
Add initial setup files
Browse files- .gitignore +2 -0
- app.py +37 -0
- requirements.txt +2 -0
- test.jpg +0 -0
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
.DS_Store
|
2 |
+
*~
|
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import coremltools as ct
|
3 |
+
import numpy as np
|
4 |
+
import requests
|
5 |
+
import huggingface_hub as hf
|
6 |
+
from huggingface_hub import hf_hub_download
|
7 |
+
from huggingface_hub import login
|
8 |
+
import os
|
9 |
+
import PIL
|
10 |
+
|
11 |
+
#login()
|
12 |
+
|
13 |
+
read_key = os.environ.get('HF_TOKEN', True)
|
14 |
+
extractor_path = hf_hub_download(repo_id="crossprism/efficientnetv221k-M", filename="efficientnetV2M21kExtractor.mlmodel", use_auth_token = read_key)
|
15 |
+
classifier_path = hf_hub_download(repo_id="crossprism/tesla_sentry_dings", filename="tesla_sentry_door_ding.mlpackage/Data/com.apple.CoreML/tesla_door_dings.mlmodel", use_auth_token = read_key)
|
16 |
+
|
17 |
+
|
18 |
+
print(f"Loading extractor...{extractor_path}")
|
19 |
+
extractor = ct.models.MLModel(extractor_path)
|
20 |
+
print(f"Loading classifier...{classifier_path}")
|
21 |
+
classifier = ct.models.MLModel(classifier_path)
|
22 |
+
|
23 |
+
def classify_image(image):
|
24 |
+
image = image.resize((480,480))
|
25 |
+
features = extractor.predict({"image":image})
|
26 |
+
print(features)
|
27 |
+
features = features["Identity"]
|
28 |
+
isDing = classifier.predict({"features":features[0]})
|
29 |
+
print(isDing)
|
30 |
+
isDing = isDing["Identity"]
|
31 |
+
return {'ding': isDing["ding"]}
|
32 |
+
|
33 |
+
image = gr.Image(type='pil')
|
34 |
+
label = gr.Label(num_top_classes=3)
|
35 |
+
|
36 |
+
gr.Interface(fn=classify_image, inputs=image, outputs=label, examples = [["test.jpg"]]).launch()
|
37 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
python==3.9
|
2 |
+
coremltools=5.1
|
test.jpg
ADDED