yolac commited on
Commit
088f723
·
verified ·
1 Parent(s): b089bd8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -38,11 +38,14 @@ class BacterialMorphologyClassifier(nn.Module):
38
  # Load the model and weights
39
  MODEL_PATH = "https://huggingface.co/yolac/BacterialMorphologyClassification/resolve/main/model.pth"
40
  logging.debug("Starting model loading...")
41
- model = BacterialMorphologyClassifier()
42
- state_dict = torch.hub.load_state_dict_from_url(MODEL_PATH, map_location=torch.device('cpu'))
43
- model.load_state_dict(state_dict, strict=False)
44
- model.eval()
45
- logging.debug("Model loaded successfully.")
 
 
 
46
 
47
  # Define image preprocessing transformations
48
  transform = transforms.Compose([
@@ -54,8 +57,10 @@ transform = transforms.Compose([
54
  # Define the prediction function
55
  def predict(image):
56
  try:
 
57
  # Preprocess the image
58
  image_tensor = transform(image).unsqueeze(0)
 
59
 
60
  # Make prediction
61
  output = model(image_tensor)
 
38
  # Load the model and weights
39
  MODEL_PATH = "https://huggingface.co/yolac/BacterialMorphologyClassification/resolve/main/model.pth"
40
  logging.debug("Starting model loading...")
41
+ try:
42
+ model = BacterialMorphologyClassifier()
43
+ state_dict = torch.hub.load_state_dict_from_url(MODEL_PATH, map_location=torch.device('cpu'))
44
+ model.load_state_dict(state_dict, strict=False)
45
+ model.eval()
46
+ logging.debug("Model loaded successfully.")
47
+ except Exception as e:
48
+ logging.error(f"Error loading the model: {str(e)}")
49
 
50
  # Define image preprocessing transformations
51
  transform = transforms.Compose([
 
57
  # Define the prediction function
58
  def predict(image):
59
  try:
60
+ logging.debug("Starting prediction...")
61
  # Preprocess the image
62
  image_tensor = transform(image).unsqueeze(0)
63
+ logging.debug("Image preprocessing completed.")
64
 
65
  # Make prediction
66
  output = model(image_tensor)