Spaces:
Sleeping
Sleeping
Commit
·
82b3c73
1
Parent(s):
4ea65e1
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,35 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import numpy as np
|
| 3 |
-
from keras.
|
| 4 |
-
from
|
| 5 |
-
from tensorflow.keras.
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
model = load_model(
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
| 27 |
predicted_class_label = class_labels[predicted_class_index]
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|