Spaces:
Sleeping
Sleeping
Create app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051import streamlit as stimport numpy as npfrom PIL import Imagefrom tensorflow.keras.models import load_modelfrom tensorflow.keras.applications.mobilenet_v2 import preprocess_inputimport joblibimport gdown
# Google Drive model URLsKNN_MODEL_URL = 'https://drive.google.com/uc?id=1TJ0KbzFw-2NfuJf67xvp-32uaYLIqpj3'EXTRACTOR_URL = 'https://drive.google.com/uc?id=1HR2Qc8Fji6RzbtG_K_sqSoiG0AQnvyZa'
# Download the model filesst.write("Downloading models...")gdown.download(KNN_MODEL_URL, 'knn_pharyngitis_model.pkl', quiet=False)gdown.download(EXTRACTOR_URL, 'mobilenetv2_feature_extractor.h5', quiet=False)st.write("Models downloaded successfully!")
# Load the saved modelsknn = joblib.load('knn_pharyngitis_model.pkl')feature_extractor = load_model('mobilenetv2_feature_extractor.h5')
# Function to preprocess the uploaded imagedef 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 imagedef 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 UIst.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}**")app.pyAdded+51