lmedz commited on
Commit
02cdb46
·
verified ·
1 Parent(s): f548c9f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -22,20 +22,26 @@ transform = transforms.Compose([
22
 
23
  class_names = ['Bad Cell', 'Good Cell'] # 適宜修正
24
 
25
- def predict(img):
26
  img_tensor = transform(img).unsqueeze(0).to(device)
27
  with torch.no_grad():
28
  logits = model(img_tensor)
29
  probs = torch.softmax(logits, dim=1).cpu().numpy().flatten()
30
- return {class_names[i]: float(probs[i]) for i in range(len(class_names))}
 
 
31
 
32
  demo = gr.Interface(
33
  fn=predict,
34
- inputs=gr.Image(type="pil"),
35
- outputs=gr.Label(num_top_classes=2),
 
 
 
36
  title="iPS Cell Quality Classifier",
37
- description="Upload a microscopy image to classify cell quality."
38
  )
39
 
 
40
  if __name__ == "__main__":
41
  demo.launch()
 
22
 
23
  class_names = ['Bad Cell', 'Good Cell'] # 適宜修正
24
 
25
+ def predict(img):def predict(img):
26
  img_tensor = transform(img).unsqueeze(0).to(device)
27
  with torch.no_grad():
28
  logits = model(img_tensor)
29
  probs = torch.softmax(logits, dim=1).cpu().numpy().flatten()
30
+ result = {class_names[i]: float(probs[i]) for i in range(len(class_names))}
31
+ return img, result # ← 画像とスコアを返す
32
+
33
 
34
  demo = gr.Interface(
35
  fn=predict,
36
+ inputs=gr.Image(type="pil", label="Input Image"),
37
+ outputs=[
38
+ gr.Image(type="pil", label="Uploaded Image"),
39
+ gr.Label(num_top_classes=2, label="Prediction")
40
+ ],
41
  title="iPS Cell Quality Classifier",
42
+ description="Upload a microscopy image. The image and predicted cell quality will be displayed."
43
  )
44
 
45
+
46
  if __name__ == "__main__":
47
  demo.launch()