AliAmr0 commited on
Commit
bf92d24
·
verified ·
1 Parent(s): 58d21ea

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import tensorflow as tf
3
+ from tensorflow.keras.applications.resnet50 import ResNet50, preprocess_input
4
+ from tensorflow.keras.preprocessing import image
5
+ import numpy as np
6
+ from PIL import Image
7
+
8
+ # Load pre-trained ResNet50 model
9
+ model = tf.keras.models.load_model("resnet50_kidney_ct_augmented.h5") # Update this path if you are using a .pb file
10
+
11
+ # Class labels (change based on your model's labels)
12
+ labels = ["Cyst", "Normal", "Stone", "Tumor"]
13
+
14
+ def predict(img):
15
+ # Resize and preprocess image to fit ResNet50 input format
16
+ img = img.resize((224, 224)) # ResNet50 expects 224x224 images
17
+ img_array = image.img_to_array(img)
18
+ img_array = np.expand_dims(img_array, axis=0)
19
+ img_array = preprocess_input(img_array)
20
+
21
+ # Model prediction
22
+ prediction = model.predict(img_array)
23
+ predicted_class = np.argmax(prediction, axis=1)
24
+
25
+ return labels[predicted_class[0]]
26
+
27
+ # Streamlit interface
28
+ st.title("TensorFlow Image Classification with ResNet50")
29
+ st.write("Upload an image to classify")
30
+
31
+ uploaded_image = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
32
+
33
+ if uploaded_image is not None:
34
+ img = Image.open(uploaded_image)
35
+ st.image(img, caption="Uploaded Image", use_column_width=True)
36
+
37
+ # Make prediction
38
+ prediction = predict(img)
39
+ st.write(f"Prediction: {prediction}")