Cheomjee commited on
Commit
6b13e81
ยท
verified ยท
1 Parent(s): 6bd26d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -3
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 label, outputs.numpy() # ์›๋ณธ ์ถœ๋ ฅ๊ฐ’์„ NumPy ๋ฐฐ์—ด๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ๋ฐ˜ํ™˜
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)