|
import streamlit as st |
|
from tensorflow import keras |
|
import numpy as np |
|
from huggingface_hub import HfFileSystem |
|
from PIL import Image |
|
|
|
|
|
fs = HfFileSystem() |
|
model_path = 'dhhd255/main_model/best_model.h5' |
|
with fs.open(model_path, 'rb') as f: |
|
model_content = f.read() |
|
|
|
|
|
with open('best_model.h5', 'wb') as f: |
|
f.write(model_content) |
|
|
|
|
|
model = keras.models.load_model('best_model.h5') |
|
|
|
|
|
def image_classifier(image): |
|
|
|
image = Image.fromarray(image) |
|
image = image.convert('L') |
|
image = image.resize((128, 128)) |
|
image = np.array(image) |
|
image = image / 255.0 |
|
image = np.expand_dims(image, axis=0) |
|
image = np.expand_dims(image, axis=-1) |
|
|
|
|
|
predictions = model.predict(image) |
|
|
|
|
|
predicted_index = np.argmax(predictions[0]) |
|
|
|
|
|
labels = ['Healthy', 'Parkinson'] |
|
predicted_label = labels[predicted_index] |
|
|
|
|
|
return predictions[0], predicted_label |
|
|
|
|
|
uploaded_file = st.file_uploader('Upload an image') |
|
if uploaded_file is not None: |
|
|
|
image = Image.open(uploaded_file) |
|
image = np.array(image) |
|
|
|
|
|
predictions, predicted_label = image_classifier(image) |
|
|
|
|
|
st.write(f'Predictions: {predictions}') |
|
st.write(f'Predicted label: {predicted_label}') |
|
|