runaksh commited on
Commit
ad69c6b
·
verified ·
1 Parent(s): 312c423

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -9
app.py CHANGED
@@ -15,23 +15,25 @@ def classify_image(image):
15
  # Convert the PIL Image to a format compatible with the feature extractor
16
  image = np.array(image)
17
  # Preprocess the image and prepare it for the model
18
- inputs = feature_extractor(images=image, return_tensors="pt")
 
19
  # Make prediction
20
  with torch.no_grad():
21
- outputs_pneumonia = model_pneumonia(**inputs)
22
  logits_pneumonia = outputs_pneumonia.logits
 
 
23
  # Retrieve the highest probability class label index
24
  predicted_class_idx_pneumonia = logits_pneumonia.argmax(-1).item()
 
25
  # Define a manual mapping of label indices to human-readable labels
26
- index_to_label = {
27
- 0: "NORMAL",
28
- 1: "PNEUMONIA"
29
- }
30
-
31
  # Convert the index to the model's class label
32
- label_pneumonia = index_to_label.get(predicted_class_idx_pneumonia, "Unknown Label")
 
33
 
34
- return label_pneumonia
35
 
36
  # Create title, description and article strings
37
  title = "Classification Demo"
 
15
  # Convert the PIL Image to a format compatible with the feature extractor
16
  image = np.array(image)
17
  # Preprocess the image and prepare it for the model
18
+ inputs_pneumonia = feature_extractor(images=image, return_tensors="pt")
19
+ inputs_tuberculosis = feature_extractor(images=image, return_tensors="pt")
20
  # Make prediction
21
  with torch.no_grad():
22
+ outputs_pneumonia = model_pneumonia(**inputs_pneumonia)
23
  logits_pneumonia = outputs_pneumonia.logits
24
+ outputs_tuberculosis = model_tuberculosis(**inputs_tuberculosis)
25
+ logits_tuberculosis = outputs_tuberculosis.logits
26
  # Retrieve the highest probability class label index
27
  predicted_class_idx_pneumonia = logits_pneumonia.argmax(-1).item()
28
+ predicted_class_idx_tuberculosis = logits_tuberculosis.argmax(-1).item()
29
  # Define a manual mapping of label indices to human-readable labels
30
+ index_to_label_pneumonia = {0: "NORMAL",1: "PNEUMONIA"}
31
+ index_to_label_tuberculosis = {0: "NORMAL",1: "TUBERCULOSIS"}
 
 
 
32
  # Convert the index to the model's class label
33
+ label_pneumonia = index_to_label_pneumonia.get(predicted_class_idx_pneumonia, "Unknown Label")
34
+ label_tuberculosis = index_to_label_tuberculosis.get(predicted_class_idx_tuberculosis, "Unknown Label")
35
 
36
+ return label_pneumonia, label_tuberculosis
37
 
38
  # Create title, description and article strings
39
  title = "Classification Demo"