File size: 1,421 Bytes
94002ab
 
82b3c73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e6d8a88
82b3c73
94002ab
82b3c73
 
 
 
 
 
 
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
import streamlit as st
import numpy as np
from tensorflow.keras.preprocessing.image import load_img, img_to_array
from tensorflow.keras.applications.densenet import preprocess_input
from tensorflow.keras.models import load_model

# Load the pre-trained model
model = load_model("./best_weights.hdf5")  # Replace with the path to your model

class_labels = {0: 'COVID19', 1: 'NORMAL', 2: 'PNEUMONIA', 3: 'TURBERCULOSIS'}

def main():
    st.title("Respiratory Symptom Prediction")
    st.write("Upload an image to predict the respiratory symptom.")

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

    if uploaded_file is not None:
        # Load and preprocess the uploaded image
        image = load_img(uploaded_file, target_size=(224, 224))
        image_array = img_to_array(image)
        image_preprocessed = preprocess_input(image_array)
        image_batch = np.expand_dims(image_preprocessed, axis=0)

        # Make predictions
        predictions = model.predict(image_batch)
        st.write(predictions)
        predicted_class_index = np.argmax(predictions)
        predicted_class_label = class_labels[predicted_class_index]

        # Display the uploaded image and prediction result
        st.image(image, caption="Uploaded Image", use_column_width=True)
        st.write(f"Predicted class label: {predicted_class_label}")

if __name__ == "__main__":
    main()