Vinit710 commited on
Commit
930fdb1
·
verified ·
1 Parent(s): 6cf56ea

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import tensorflow as tf
3
+ from PIL import Image
4
+ import numpy as np
5
+
6
+ # Load your trained model
7
+ @st.cache_resource
8
+ def load_model():
9
+ model = tf.keras.models.load_model("ocular_model.h5")
10
+ return model
11
+
12
+ model = load_model()
13
+
14
+ # Define the class names (adjust this based on your specific model's output)
15
+ CLASS_NAMES = ['No Diabetes', 'Diabetes']
16
+
17
+ # Preprocess the image
18
+ def preprocess_image(image: Image.Image):
19
+ image = image.resize((224, 224)) # Resize image to the expected input size
20
+ image = np.array(image) / 255.0 # Normalize to [0, 1]
21
+ image = np.expand_dims(image, axis=0) # Add batch dimension
22
+ return image
23
+
24
+ # Streamlit UI
25
+ st.title("Ocular to Diabetes Prediction")
26
+ st.write("Upload an image of an eye to predict the risk of diabetes.")
27
+
28
+ # Uploading the image
29
+ uploaded_file = st.file_uploader("Choose an eye image...", type=["jpg", "jpeg", "png"])
30
+
31
+ if uploaded_file is not None:
32
+ # Load and display the image
33
+ image = Image.open(uploaded_file)
34
+ st.image(image, caption='Uploaded Image', use_column_width=True)
35
+
36
+ # Preprocess and predict
37
+ st.write("Processing the image...")
38
+ image = preprocess_image(image)
39
+ predictions = model.predict(image)
40
+ score = tf.nn.softmax(predictions[0])
41
+
42
+ # Display prediction result
43
+ st.write(f"Prediction: {CLASS_NAMES[np.argmax(score)]}")
44
+ st.write(f"Confidence: {100 * np.max(score):.2f}%")