File size: 1,452 Bytes
bf92d24
 
9899694
bf92d24
 
 
b8d882d
bf92d24
9899694
ae3babb
9899694
bf92d24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import tensorflow as tf
from tensorflow.keras.applications.resnet50 import preprocess_input
from tensorflow.keras.preprocessing import image
import numpy as np
from PIL import Image
from huggingface_hub import hf_hub_download

# Download the model from Hugging Face
model_path = hf_hub_download(repo_id="AliAmr0/Kidney-Classification-Using-Resnet50", filename="resnet50_kidney_ct_augmented.h5")
model = tf.keras.models.load_model(model_path)

# Class labels (change based on your model's labels)
labels = ["Cyst", "Normal", "Stone", "Tumor"]

def predict(img):
    # Resize and preprocess image to fit ResNet50 input format
    img = img.resize((224, 224))  # ResNet50 expects 224x224 images
    img_array = image.img_to_array(img)
    img_array = np.expand_dims(img_array, axis=0)
    img_array = preprocess_input(img_array)

    # Model prediction
    prediction = model.predict(img_array)
    predicted_class = np.argmax(prediction, axis=1)
    
    return labels[predicted_class[0]]

# Streamlit interface
st.title("TensorFlow Image Classification with ResNet50")
st.write("Upload an image to classify")

uploaded_image = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])

if uploaded_image is not None:
    img = Image.open(uploaded_image)
    st.image(img, caption="Uploaded Image", use_column_width=True)
    
    # Make prediction
    prediction = predict(img)
    st.write(f"Prediction: {prediction}")