ashiqu-ali commited on
Commit
546f0b1
1 Parent(s): 0a738e2

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -64
app.py DELETED
@@ -1,64 +0,0 @@
1
- import os
2
- import streamlit as st
3
- import tensorflow as tf
4
- import numpy as np
5
-
6
- # Loading the saved model
7
- model = tf.keras.models.load_model('model.h5')
8
-
9
- def predict(input_image):
10
- try:
11
- # Preprocessing
12
- input_image = tf.convert_to_tensor(input_image)
13
- input_image = tf.image.resize(input_image, [224, 224])
14
- input_image = tf.expand_dims(input_image, 0) / 255.0
15
-
16
- # Prediction
17
- predictions = model.predict(input_image)
18
- labels = ['Cataract', 'Conjunctivitis', 'Glaucoma', 'Normal']
19
-
20
- # Get confidence score for each class
21
- disease_confidence = {label: np.round(predictions[0][idx] * 100, 3) for idx, label in enumerate(labels)}
22
-
23
- # Get confidence percentage for the "Normal" class
24
- normal_confidence = disease_confidence['Normal']
25
-
26
- # Check if Normal confidence is greater than 50%
27
- if normal_confidence > 50:
28
- return f"""Congrats! no disease detected
29
- Normal with confidence: {normal_confidence}%"""
30
-
31
-
32
- output_lines = [f"\n{disease}: {confidence}%" for disease, confidence in disease_confidence.items()]
33
- output_string = "\n".join(output_lines[:-1])
34
- return output_string
35
-
36
-
37
- except Exception as e:
38
- return f"An error occurred: {e}"
39
-
40
- # Example images directory
41
- examples = [os.path.join("example", file) for file in os.listdir("example")]
42
-
43
- # Streamlit app
44
- st.title("👁️ Eye Disease Detection")
45
- st.write("This model identifies common eye diseases such as Cataract, Conjunctivitis, and Glaucoma. Upload an eye image to see how the model classifies its condition.")
46
-
47
- uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png"])
48
-
49
- if uploaded_file is not None:
50
- # Display the uploaded image
51
- image = tf.image.decode_image(uploaded_file.read(), channels=3)
52
- image_np = image.numpy()
53
- st.image(image_np, caption='Uploaded Image.', use_column_width=True)
54
-
55
- # Perform prediction
56
- prediction = predict(image_np)
57
- st.write("Prediction:")
58
- st.write(prediction)
59
-
60
- # Display examples images
61
- st.write("Examples:")
62
- cols = st.columns(len(examples))
63
- for idx, example in enumerate(examples):
64
- cols[idx].image(example, caption=os.path.basename(example))