File size: 2,312 Bytes
d2192a3
 
 
 
 
 
 
424c8a2
 
 
45764a6
a18fbad
 
 
 
 
 
424c8a2
a18fbad
 
 
 
 
 
 
 
 
 
 
 
 
 
d2192a3
424c8a2
d2192a3
 
 
 
 
 
424c8a2
d2192a3
 
 
 
 
 
 
a18fbad
424c8a2
d2192a3
424c8a2
d2192a3
 
 
 
 
 
a18fbad
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import streamlit as st
import numpy as np
from PIL import Image
from tensorflow.keras.models import load_model
from tensorflow.keras.applications.mobilenet_v2 import preprocess_input
import joblib

# Paths to the saved models
KNN_MODEL_PATH = './knn_pharyngitis_model.pkl'
EXTRACTOR_PATH = './mobilenetv2_feature_extractor.h5'

# Display a welcome message and note
st.title("Pharyngitis Classification App")
st.write("""
**Please wait while the models are being loaded.**
""")

# Load the saved models
with st.spinner("Please wait for a while..."):
    knn = joblib.load(KNN_MODEL_PATH)
    feature_extractor = load_model(EXTRACTOR_PATH)

st.success("Models loaded successfully!")

# Display additional information
st.markdown("""
### Note:
- This application predicts whether the uploaded throat image shows signs of *pharyngitis* or not.
- **Accuracy:** Approximately 80%.
- **Disclaimer:** This tool is not a substitute for a medical professional's advice. 
  Please consult a physician if you experience any throat-related issues.
""")

# Function to preprocess the uploaded image
def preprocess_image(image):
    img = image.resize((224, 224))  # Resize to match MobileNetV2 input size
    img_array = np.array(img)
    img_array = preprocess_input(img_array)  # Apply MobileNetV2 preprocessing
    return np.expand_dims(img_array, axis=0)

# Function to classify the image
def classify_image(image):
    processed_image = preprocess_image(image)
    features = feature_extractor.predict(processed_image)
    prediction = knn.predict(features)
    return "Pharyngitis" if prediction[0] == 1 else "No Pharyngitis"

# Streamlit app UI
st.write("### Upload an image to classify it as 'Pharyngitis' or 'No Pharyngitis'.")

uploaded_file = st.file_uploader("Choose an image file", type=["jpg", "jpeg", "png"])

if uploaded_file is not None:
    # Load the uploaded image
    image = Image.open(uploaded_file)
    st.image(image, caption="Uploaded Image", use_column_width=True)

    # Classify the image
    st.write("### Classifying...")
    with st.spinner("Analyzing the image..."):
        prediction = classify_image(image)
    st.success(f"Prediction: **{prediction}**")

# Footer with a link to your LinkedIn profile
st.markdown("""
---
Made with ❤️ by [Haris](https://www.linkedin.com/in/h4r1s)
""")