ikhlasulakmalh commited on
Commit
82b3c73
·
1 Parent(s): 4ea65e1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -25
app.py CHANGED
@@ -1,28 +1,35 @@
1
  import streamlit as st
2
  import numpy as np
3
- from keras.models import load_model
4
- from PIL import Image
5
- from tensorflow.keras.applications.resnet50 import preprocess_input
6
-
7
-
8
- model = load_model('./best_weights.hdf5')
9
-
10
- st.title('Respiratory Symptom Detection')
11
-
12
- uploaded_file = st.file_uploader("Choose an image: ", type="jpg")
13
-
14
- if uploaded_file is not None:
15
- img = Image.open(uploaded_file)
16
- img = img.resize((224, 224))
17
- img_array = np.array(img)
18
-
19
- # If your model expects a 3-channel RGB image, expand dimensions like this:
20
- img_array = np.expand_dims(img_array, axis=0) # Adding batch dimension
21
- image_preprocessed = preprocess_input(img_array)
22
-
23
- if st.button('Predict'):
24
- prediction = model.predict(image_preprocessed)
25
- predicted_class_index = np.argmax(prediction)
26
- class_labels = {0: 'COVID19', 1: 'NORMAL', 2: 'PNEUMONIA', 3: 'TUBERCULOSIS'}
 
27
  predicted_class_label = class_labels[predicted_class_index]
28
- st.write(predicted_class_label)
 
 
 
 
 
 
 
1
  import streamlit as st
2
  import numpy as np
3
+ from tensorflow.keras.preprocessing.image import load_img, img_to_array
4
+ from tensorflow.keras.applications.densenet import preprocess_input
5
+ from tensorflow.keras.models import load_model
6
+
7
+ # Load the pre-trained model
8
+ model = load_model("./best_weights.hdf5") # Replace with the path to your model
9
+
10
+ class_labels = {0: 'COVID19', 1: 'NORMAL', 2: 'PNEUMONIA', 3: 'TURBERCULOSIS'}
11
+
12
+ def main():
13
+ st.title("Respiratory Symptom Prediction")
14
+ st.write("Upload an image to predict the respiratory symptom.")
15
+
16
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
17
+
18
+ if uploaded_file is not None:
19
+ # Load and preprocess the uploaded image
20
+ image = load_img(uploaded_file, target_size=(224, 224))
21
+ image_array = img_to_array(image)
22
+ image_preprocessed = preprocess_input(image_array)
23
+ image_batch = np.expand_dims(image_preprocessed, axis=0)
24
+
25
+ # Make predictions
26
+ predictions = model.predict(image_batch)
27
+ predicted_class_index = np.argmax(predictions)
28
  predicted_class_label = class_labels[predicted_class_index]
29
+
30
+ # Display the uploaded image and prediction result
31
+ st.image(image, caption="Uploaded Image", use_column_width=True)
32
+ st.write(f"Predicted class label: {predicted_class_label}")
33
+
34
+ if __name__ == "__main__":
35
+ main()