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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -16,24 +16,25 @@ 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
 
36
- return label_pneumonia, label_tuberculosis
37
 
38
  # Create title, description and article strings
39
  title = "Classification Demo"
 
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
 
39
  # Create title, description and article strings
40
  title = "Classification Demo"