AliAmr0/Kidney-Classification
0
1import streamlit as st2import tensorflow as tf3from tensorflow.keras.applications.resnet50 import preprocess_input4from tensorflow.keras.preprocessing import image5import numpy as np6from PIL import Image7from huggingface_hub import hf_hub_download8 9# Download the model from Hugging Face10model_path = hf_hub_download(repo_id="AliAmr0/Kidney-Classification-Using-Resnet50", filename="resnet50_kidney_ct_augmented.h5")11model = tf.keras.models.load_model(model_path)12 13# Class labels (change based on your model's labels)14labels = ["Cyst", "Normal", "Stone", "Tumor"]15 16def predict(img):17 # Resize and preprocess image to fit ResNet50 input format18 img = img.resize((224, 224)) # ResNet50 expects 224x224 images19 img_array = image.img_to_array(img)20 img_array = np.expand_dims(img_array, axis=0)21 img_array = preprocess_input(img_array)22 23 # Model prediction24 prediction = model.predict(img_array)25 predicted_class = np.argmax(prediction, axis=1)26 27 return labels[predicted_class[0]]28 29# Streamlit interface30st.title("TensorFlow Image Classification with ResNet50")31st.write("Upload an image to classify")32 33uploaded_image = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])34 35if uploaded_image is not None:36 img = Image.open(uploaded_image)37 st.image(img, caption="Uploaded Image", use_column_width=True)38 39 # Make prediction40 prediction = predict(img)41 st.write(f"Prediction: {prediction}")42 