nekofura commited on
Commit
cb14e5c
1 Parent(s): 14be786

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -10
app.py CHANGED
@@ -12,10 +12,8 @@ class_names = [
12
  "tooth_discoloration"
13
  ]
14
 
15
- num_classes = len(class_names)
16
-
17
  model = models.resnet50(weights=None)
18
- model.fc = torch.nn.Linear(model.fc.in_features, num_classes)
19
 
20
  model.load_state_dict(torch.load('best_model.pth', map_location=torch.device('cpu')))
21
  model.eval()
@@ -26,7 +24,7 @@ preprocess = transforms.Compose([
26
  transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
27
  ])
28
 
29
- def predict_image(image, model=model, preprocess=preprocess, class_names=class_names):
30
  processed_image = preprocess(image).unsqueeze(0)
31
 
32
  with torch.no_grad():
@@ -37,11 +35,11 @@ def predict_image(image, model=model, preprocess=preprocess, class_names=class_n
37
  return predicted_class
38
 
39
  iface = gr.Interface(
40
- fn=predict_image,
41
- inputs=gr.inputs.Image(type='pil'),
42
- outputs=gr.outputs.Label(num_top_classes=1),
43
- title="Klasifikasi Gambar Medis",
44
- description="Upload gambar untuk memprediksi kelasnya."
45
  )
46
 
47
- iface.launch()
 
12
  "tooth_discoloration"
13
  ]
14
 
 
 
15
  model = models.resnet50(weights=None)
16
+ model.fc = torch.nn.Linear(model.fc.in_features, len(class_names))
17
 
18
  model.load_state_dict(torch.load('best_model.pth', map_location=torch.device('cpu')))
19
  model.eval()
 
24
  transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
25
  ])
26
 
27
+ def predict_image(image):
28
  processed_image = preprocess(image).unsqueeze(0)
29
 
30
  with torch.no_grad():
 
35
  return predicted_class
36
 
37
  iface = gr.Interface(
38
+ fn=predict_image,
39
+ inputs=gr.Image(type="pil"),
40
+ outputs="label",
41
+ title="Medical Image Classification",
42
+ description="Upload an image to predict its class."
43
  )
44
 
45
+ iface.launch()