yolac commited on
Commit
cf86671
·
verified ·
1 Parent(s): 02c0ae0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -54,24 +54,30 @@ def predict(image):
54
  # Make prediction
55
  output = model(image_tensor)
56
  prediction = output.argmax().item()
 
57
 
 
 
 
 
58
  # Class mapping
59
  class_labels = {0: 'cocci', 1: 'bacilli', 2: 'spirilla'}
60
 
61
  # Return prediction result
62
- return class_labels[prediction], output.max().item()
63
  except Exception as e:
64
  return {'error': str(e)}
65
 
 
66
  # Create the Gradio interface
67
  iface = gr.Interface(
68
  fn=predict,
69
  inputs=gr.Image(type="pil", label="Upload an image"),
70
  outputs=[gr.Label(num_top_classes=3, label="Predicted Class"), gr.Number(label="Confidence")],
71
  examples=[
72
- "https://huggingface.co/datasets/yolac/BacterialMorphologyClassification/viewer/default/train?p=2&row=201&image-viewer=8FBAF2C52C256A392660811C5659788734821C3A",
73
- "https://huggingface.co/datasets/yolac/BacterialMorphologyClassification/viewer/default/train?p=2&image-viewer=AEF1AA2978EEB77362DA9CCC8792473666F7CDC6",
74
- "https://huggingface.co/datasets/yolac/BacterialMorphologyClassification/viewer/default/train?image-viewer=C98E6CFAB26ECC3808C63185F6CCE90DE4E7C442"
75
  ]
76
  )
77
 
 
54
  # Make prediction
55
  output = model(image_tensor)
56
  prediction = output.argmax().item()
57
+ confidence = output.max().item()
58
 
59
+ # Print debugging information
60
+ print(f"Predicted: {prediction}, Confidence: {confidence}")
61
+ print(f"Model Output: {output}")
62
+
63
  # Class mapping
64
  class_labels = {0: 'cocci', 1: 'bacilli', 2: 'spirilla'}
65
 
66
  # Return prediction result
67
+ return class_labels[prediction], confidence
68
  except Exception as e:
69
  return {'error': str(e)}
70
 
71
+
72
  # Create the Gradio interface
73
  iface = gr.Interface(
74
  fn=predict,
75
  inputs=gr.Image(type="pil", label="Upload an image"),
76
  outputs=[gr.Label(num_top_classes=3, label="Predicted Class"), gr.Number(label="Confidence")],
77
  examples=[
78
+ "https://huggingface.co/datasets/yolac/BacterialMorphologyClassification/resolve/main/img%20290.jpg",
79
+ "https://huggingface.co/datasets/yolac/BacterialMorphologyClassification/resolve/main/img%20565.jpg",
80
+ "https://huggingface.co/datasets/yolac/BacterialMorphologyClassification/resolve/main/img%208.jpg"
81
  ]
82
  )
83