runaksh commited on
Commit
fbb55a1
·
verified ·
1 Parent(s): f89e4ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -16,23 +16,23 @@ def classify_image(image):
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
- label = label_pneumonia
36
 
37
  return label
38
 
 
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
+ label = label_pneumonia+" "+label_tuberculosis
36
 
37
  return label
38