hamaadayubkhan commited on
Commit
26181d0
·
verified ·
1 Parent(s): 16dd709
Files changed (1) hide show
  1. app.py +12 -12
app.py CHANGED
@@ -80,8 +80,7 @@ def classify_ecg(image):
80
  logits = outputs.logits # Get the logits
81
  predicted_class = torch.argmax(logits, dim=1).item() # Get the index of the highest score
82
 
83
- # Return heart status based on predicted class
84
- return "Clear" if predicted_class == 1 else "Unclear" # Adjust based on your model's labels
85
  except Exception as e:
86
  st.error(f"Error during model inference: {str(e)}")
87
  return "Error in classification."
@@ -102,13 +101,14 @@ def validate_ecg(image):
102
  if mean_pixel_value > 200: # Adjust threshold based on your requirements
103
  return False, "Image is too bright."
104
 
105
- # Additional checks could be implemented here
106
  return True, ""
107
 
108
- def mark_issues(image, issue):
109
  draw = ImageDraw.Draw(image)
110
- # Drawing a red rectangle around the area with an issue
111
- draw.rectangle([0, 0, image.size[0], image.size[1]], outline="red", width=5)
 
 
112
  return image
113
 
114
  # Streamlit UI for ECG Upload
@@ -125,13 +125,13 @@ if uploaded_file:
125
  else:
126
  st.image(image, caption="Uploaded ECG Image.", use_column_width=True)
127
  # Make predictions using the Hugging Face model
128
- heart_status = classify_ecg(image)
129
- if heart_status == "Unclear":
130
- marked_image = mark_issues(image.copy(), issue)
131
- st.image(marked_image, caption="Marked ECG Image with Issues.", use_column_width=True)
132
- st.write(f"Predicted heart status: {heart_status}. Potential issue: {issue}")
133
  else:
134
- st.write(f"Predicted heart status: {heart_status}")
135
 
136
  # Text input for additional questions
137
  user_question = st.text_input("Ask any question about your ECG result", key="user_question")
 
80
  logits = outputs.logits # Get the logits
81
  predicted_class = torch.argmax(logits, dim=1).item() # Get the index of the highest score
82
 
83
+ return predicted_class # Return the class index for further processing
 
84
  except Exception as e:
85
  st.error(f"Error during model inference: {str(e)}")
86
  return "Error in classification."
 
101
  if mean_pixel_value > 200: # Adjust threshold based on your requirements
102
  return False, "Image is too bright."
103
 
 
104
  return True, ""
105
 
106
+ def highlight_issue(image):
107
  draw = ImageDraw.Draw(image)
108
+ width, height = image.size
109
+
110
+ # Draw a red line across the middle of the image to indicate an issue
111
+ draw.line([(0, height // 2), (width, height // 2)], fill="red", width=5)
112
  return image
113
 
114
  # Streamlit UI for ECG Upload
 
125
  else:
126
  st.image(image, caption="Uploaded ECG Image.", use_column_width=True)
127
  # Make predictions using the Hugging Face model
128
+ predicted_class = classify_ecg(image)
129
+ if predicted_class == 0: # Assuming 0 means "Unclear"
130
+ highlighted_image = highlight_issue(image.copy())
131
+ st.image(highlighted_image, caption="Marked ECG Image with Issues.", use_column_width=True)
132
+ st.write(f"Predicted heart status: Unclear. Potential issue detected.")
133
  else:
134
+ st.write(f"Predicted heart status: Clear.")
135
 
136
  # Text input for additional questions
137
  user_question = st.text_input("Ask any question about your ECG result", key="user_question")