Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,6 @@
|
|
| 1 |
-
import
|
| 2 |
from transformers import pipeline
|
| 3 |
-
|
| 4 |
-
import os
|
| 5 |
-
|
| 6 |
-
#openai.api_key = os.getenv("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")
|
| 7 |
|
| 8 |
# Load the pre-trained image classification pipeline
|
| 9 |
pipe = pipeline("image-classification", model="ALM-AHME/convnextv2-large-1k-224-finetuned-BreastCancer-Classification-BreakHis-AH-60-20-20")
|
|
@@ -31,50 +28,40 @@ def classify_mammogram(img):
|
|
| 31 |
|
| 32 |
return f"Predicted Class: {predicted_label}\nClassification: {classification}\nConfidence: {confidence:.2f}"
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
# "content": f""" You are a breast cancer specialist and you have been given a recent breast cancer result of a patient and here are the results:
|
| 38 |
-
# Predicted Class: {predicted_label}\nClassification: {classification}\nConfidence: {confidence:.2f}
|
| 39 |
-
|
| 40 |
-
# You have to give a clear explanations about their screening results, potential next steps, and relevant information about breast health based on the scanned mammogram and provide reference to things like "Retrieve Similar Cases," "Explain Diagnostic," "Treatment Recommendations," "Prognosis Analysis," and "Clinical Trial Matching."
|
| 41 |
|
| 42 |
-
|
| 43 |
-
# Good Luck!
|
| 44 |
-
|
| 45 |
-
# """
|
| 46 |
-
# }
|
| 47 |
-
# completion = openai.ChatCompletion.create(
|
| 48 |
-
# model="gpt-3.5-turbo",
|
| 49 |
-
# messages=[user_message]
|
| 50 |
-
# )
|
| 51 |
-
# result= completion.choices[0].message.content.strip()
|
| 52 |
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
)
|
| 78 |
)
|
| 79 |
-
|
| 80 |
-
iface.launch(inbrowser=True)
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
+
from PIL import Image
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# Load the pre-trained image classification pipeline
|
| 6 |
pipe = pipeline("image-classification", model="ALM-AHME/convnextv2-large-1k-224-finetuned-BreastCancer-Classification-BreakHis-AH-60-20-20")
|
|
|
|
| 28 |
|
| 29 |
return f"Predicted Class: {predicted_label}\nClassification: {classification}\nConfidence: {confidence:.2f}"
|
| 30 |
|
| 31 |
+
# Streamlit app
|
| 32 |
+
st.title("Enhanced Protocol for Breast Cancer Detection: Streamlining Decisions from Mammograms")
|
| 33 |
+
st.write("Upload an image of a mammogram, and the model will predict whether it is benign or malignant.")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
if uploaded_file is not None:
|
| 38 |
+
image = Image.open(uploaded_file)
|
| 39 |
+
st.image(image, caption='Uploaded Image.', use_column_width=True)
|
| 40 |
+
st.write("Classifying...")
|
| 41 |
+
|
| 42 |
+
classification_result = classify_mammogram(image)
|
| 43 |
+
st.write(classification_result)
|
| 44 |
|
| 45 |
+
st.write(
|
| 46 |
+
"""
|
| 47 |
+
<div style='display: flex; justify-content: space-between;'>
|
| 48 |
+
<div style='width: 48%;'>
|
| 49 |
+
<p style='font-size: 18px; font-weight: bold;'>Malignant</p>
|
| 50 |
+
<p style='font-size: 16px;'>
|
| 51 |
+
Non-suspicious: The AI is confident that no suspicious signs are present.<br>
|
| 52 |
+
High risk: The AI is confident that the results are highly suspicious.<br>
|
| 53 |
+
Indeterminate: The AI is uncertain and not confident in making a definitive classification.
|
| 54 |
+
</p>
|
| 55 |
+
</div>
|
| 56 |
+
<div style='width: 48%;'>
|
| 57 |
+
<p style='font-size: 18px; font-weight: bold;'>Benign</p>
|
| 58 |
+
<p style='font-size: 16px;'>
|
| 59 |
+
Suspicious: AI is not that confident. Further Supervision is needed.<br>
|
| 60 |
+
Non-Suspicious: AI is confident that there is nothing to worry about.<br>
|
| 61 |
+
No Risk: AI is confident. No direct supervision is needed.
|
| 62 |
+
</p>
|
| 63 |
+
</div>
|
| 64 |
+
</div>
|
| 65 |
+
""",
|
| 66 |
+
unsafe_allow_html=True
|
|
|
|
| 67 |
)
|
|
|
|
|
|