Update app.py
Browse files
app.py
CHANGED
|
@@ -16,7 +16,8 @@ transform = transforms.Compose([
|
|
| 16 |
|
| 17 |
# ํด๋์ค ์ด๋ฆ ๋ฆฌ์คํธ ์ ์
|
| 18 |
class_names = ['disposablecup', 'envmark', 'label', 'mug', 'nonlabel', 'reusablecup']
|
| 19 |
-
|
|
|
|
| 20 |
def predict(image):
|
| 21 |
image = transform(image).unsqueeze(0)
|
| 22 |
with torch.no_grad():
|
|
@@ -25,9 +26,10 @@ def predict(image):
|
|
| 25 |
_, predicted = torch.max(outputs, 1)
|
| 26 |
label = class_names[predicted.item()]
|
| 27 |
print("Predicted label:", label)
|
| 28 |
-
|
|
|
|
| 29 |
# ์์ธก ๊ฒฐ๊ณผ์ ์๋ณธ ์ถ๋ ฅ๊ฐ์ ๋ชจ๋ ๋ฐํ
|
| 30 |
-
return
|
| 31 |
|
| 32 |
# Gradio ์ธํฐํ์ด์ค ์ค์ (๋ ๊ฐ์ ์ถ๋ ฅ)
|
| 33 |
iface = gr.Interface(fn=predict, inputs=gr.Image(type='pil'), outputs=['label', 'numpy'], live=True)
|
|
|
|
| 16 |
|
| 17 |
# ํด๋์ค ์ด๋ฆ ๋ฆฌ์คํธ ์ ์
|
| 18 |
class_names = ['disposablecup', 'envmark', 'label', 'mug', 'nonlabel', 'reusablecup']
|
| 19 |
+
class_ok = [ 'envmark','mug', 'nonlabel', 'reusablecup']
|
| 20 |
+
class_notok = ['disposablecup', 'label']
|
| 21 |
def predict(image):
|
| 22 |
image = transform(image).unsqueeze(0)
|
| 23 |
with torch.no_grad():
|
|
|
|
| 26 |
_, predicted = torch.max(outputs, 1)
|
| 27 |
label = class_names[predicted.item()]
|
| 28 |
print("Predicted label:", label)
|
| 29 |
+
if label in class_ok : result = "Mission Successed (+1p)"
|
| 30 |
+
else : result = "Mission Failed (-)"
|
| 31 |
# ์์ธก ๊ฒฐ๊ณผ์ ์๋ณธ ์ถ๋ ฅ๊ฐ์ ๋ชจ๋ ๋ฐํ
|
| 32 |
+
return result, outputs.numpy() # ์๋ณธ ์ถ๋ ฅ๊ฐ์ NumPy ๋ฐฐ์ด๋ก ๋ณํํ์ฌ ๋ฐํ
|
| 33 |
|
| 34 |
# Gradio ์ธํฐํ์ด์ค ์ค์ (๋ ๊ฐ์ ์ถ๋ ฅ)
|
| 35 |
iface = gr.Interface(fn=predict, inputs=gr.Image(type='pil'), outputs=['label', 'numpy'], live=True)
|