File size: 3,231 Bytes
e5e39f1
 
 
 
 
 
 
 
 
 
 
 
 
 
12d77f1
1ee2406
 
12d77f1
 
 
 
1ee2406
 
 
 
 
 
12d77f1
1ee2406
 
 
 
 
12d77f1
1ee2406
 
 
 
12d77f1
a1b91a6
e5e39f1
 
a1b91a6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e5e39f1
 
 
 
 
 
 
 
a1b91a6
e5e39f1
a1b91a6
2982642
a1b91a6
 
 
 
 
 
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import streamlit as st
from PIL import Image, ImageOps
import numpy as np
import pandas as pd
import tensorflow as tf  # Use TensorFlow's Keras API

# Load the TensorFlow Keras model
model = tf.keras.models.load_model('gastrointestinal_model.h5', compile=False)

# Load class names
with open('labels.txt', 'r') as f:
    class_names = f.readlines()

# Function to predict gastrointestinal conditions
def predict_gastrointestinal(img):
    np.set_printoptions(suppress=True)
    data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
    size = (224, 224)
    image_PIL = ImageOps.fit(img, size, Image.LANCZOS)
    image_array = np.asarray(image_PIL)
    normalized_image_array = (image_array.astype(np.float32) / 127.0) - 1
    data[0] = normalized_image_array
    prediction = model.predict(data)
    index = np.argmax(prediction)
    class_name = class_names[index].strip()
    confidence_score = prediction[0][index]
    other_class = [name for i, name in enumerate(class_names) if i != index][0].strip()
    
    result = {
        "Labels": [class_name, other_class],
        "Confidence Score": [confidence_score * 100, (1 - confidence_score) * 100],
        "Total": 100
    }
    
    if class_name == "Normal":
        prediction_text = "The image is classified as Normal."
    else:
        prediction_text = f"The image shows signs of {class_name}."
    
    return prediction_text

# Streamlit app
st.title("Gastrointestinal Classification Web App")

st.write("""
Welcome to the Gastrointestinal Classification Web App! This tool allows you to upload images of gastrointestinal conditions and receive classification results.

### How to Use:

1. **Upload an Image**: Click the "Upload a gastrointestinal image..." button to select and upload an image file in JPG, JPEG, or PNG format.

2. **View Classification**: Once the image is uploaded, it will be processed, and the app will classify it into one of the gastrointestinal conditions: Normal, Ulcerative Colitis, Polyp, or Esophagitis.

3. **See Results**: The app will display the classification result along with a confidence score.

### Next Steps:

- **For Medical Advice**: If the classification suggests a potential issue, we recommend consulting with a healthcare professional for a thorough examination and diagnosis.
  
- **Upload More Images**: Feel free to upload additional images if you wish to check more samples.

- **Contact Support**: If you encounter any issues or have questions about the app, please contact our support team for assistance.

Thank you for using our Gastrointestinal Classification Web App!
""")

uploaded_file = st.file_uploader("Upload a gastrointestinal image...", type=["jpg", "jpeg", "png"])

if uploaded_file is not None:
    image = Image.open(uploaded_file)
    st.image(image, caption='Uploaded Image', use_column_width=True)
    st.write("Classifying...")

    prediction = predict_gastrointestinal(image)
    st.write(prediction)
    
st.write("""
    **Next Steps:**
    
    - If the result indicates a condition of concern, please seek advice from a healthcare professional.
    - You can upload more images for further classification.
    - For any issues or questions, reach out to our support team.
    """)