Spaces:
Runtime error
Runtime error
import numpy as np | |
import streamlit as st | |
import tensorflow as tf | |
from PIL import Image | |
LABELS = [0, 1, 2, 3, 4] | |
st.title("Surrey 2023 - Diabetes Grading") | |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"]) | |
# Load your TensorFlow model | |
model = tf.keras.models.load_model("model/kd_model") | |
def preprocess_image(image, target_size=(224, 224)): | |
image = image.resize(target_size) | |
image_array = np.array(image) / 255.0 | |
return np.expand_dims(image_array, axis=0) | |
col1, col2 = st.columns(2) | |
if uploaded_file is not None: | |
image = Image.open(uploaded_file).convert('RGB') | |
col1.image(image, caption="Uploaded Image", use_column_width=True) | |
if st.button("Classify"): | |
preprocessed_image = preprocess_image(image) | |
predictions = model.predict(preprocessed_image) | |
top_prediction = np.argmax(predictions[0]) | |
predicted_class = LABELS[top_prediction] | |
col2.write(f"Predicted class: {predicted_class}") | |
else: | |
col1.write("Upload an image to see the classification") | |
col2.write("Prediction will appear here") | |