Spaces:
Sleeping
Sleeping
fix model path, added example and class names
Browse files- __pycache__/app.cpython-310.pyc +0 -0
- app.py +14 -7
- hammel.png +0 -0
- led.jpg +0 -0
- mosfet.jpg +0 -0
- screwdriver.jpg +0 -0
__pycache__/app.cpython-310.pyc
ADDED
Binary file (1.37 kB). View file
|
|
app.py
CHANGED
@@ -1,12 +1,18 @@
|
|
1 |
import pathlib
|
2 |
import gradio as gr
|
3 |
-
from fastai.vision.all import *
|
4 |
-
|
5 |
# to solve the mismatch between windows (local) system and huggingspace (linux)
|
|
|
6 |
plt = platform.system()
|
7 |
if plt == 'Linux': pathlib.WindowsPath = pathlib.PosixPath
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
-
learn = load_learner('
|
10 |
labels = learn.dls.vocab
|
11 |
|
12 |
def predict(img):
|
@@ -16,11 +22,12 @@ def predict(img):
|
|
16 |
|
17 |
iface = gr.Interface(
|
18 |
fn=predict,
|
19 |
-
inputs=gr.components.Image(shape=(
|
20 |
outputs=gr.components.Label(num_top_classes=3),
|
21 |
-
description="
|
22 |
-
article="<p style='text-align: center'
|
23 |
-
|
|
|
24 |
)
|
25 |
|
26 |
iface.launch(enable_queue=True)
|
|
|
1 |
import pathlib
|
2 |
import gradio as gr
|
|
|
|
|
3 |
# to solve the mismatch between windows (local) system and huggingspace (linux)
|
4 |
+
import platform
|
5 |
plt = platform.system()
|
6 |
if plt == 'Linux': pathlib.WindowsPath = pathlib.PosixPath
|
7 |
+
elif plt == 'Windows': pathlib.PosixPath = pathlib.WindowsPath
|
8 |
+
|
9 |
+
from fastai.vision.all import *
|
10 |
+
|
11 |
+
|
12 |
+
|
13 |
+
class_names = ["resistor", "bipolar transistor", "mosfet", "capacitor", "inductor", "wire", "led", "diode", "thermistor", "switch", "battery", "hammer", "screwdriver", "scissors", "wrench", "mallet", "axe"]
|
14 |
|
15 |
+
learn = load_learner('model.pkl')
|
16 |
labels = learn.dls.vocab
|
17 |
|
18 |
def predict(img):
|
|
|
22 |
|
23 |
iface = gr.Interface(
|
24 |
fn=predict,
|
25 |
+
inputs=gr.components.Image(shape=(224, 224)),
|
26 |
outputs=gr.components.Label(num_top_classes=3),
|
27 |
+
description="Tool Classifier",
|
28 |
+
article=f"<p style='text-align: center'>{', '.join(class_names)}</p>",
|
29 |
+
examples=[["mosfet.jpg", "screwdriver.jpg", "hammel.png", "led.jpg"]],
|
30 |
+
live=True,
|
31 |
)
|
32 |
|
33 |
iface.launch(enable_queue=True)
|
hammel.png
ADDED
led.jpg
ADDED
mosfet.jpg
ADDED
screwdriver.jpg
ADDED