Spaces:
Sleeping
Sleeping
File size: 1,622 Bytes
d2192a3 424c8a2 45764a6 424c8a2 d2192a3 424c8a2 d2192a3 424c8a2 d2192a3 424c8a2 d2192a3 424c8a2 d2192a3 424c8a2 |
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 |
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'
# Load the saved models
st.write("Loading models...")
knn = joblib.load(KNN_MODEL_PATH)
feature_extractor = load_model(EXTRACTOR_PATH)
st.write("Models loaded successfully!")
# 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.title("Pharyngitis Classification App")
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...")
prediction = classify_image(image)
st.write(f"Prediction: **{prediction}**")
|