ryefoxlime commited on
Commit
7bf2557
·
1 Parent(s): ff86231

Delete PneumoniaDetection.py

Browse files
Files changed (1) hide show
  1. PneumoniaDetection.py +0 -86
PneumoniaDetection.py DELETED
@@ -1,86 +0,0 @@
1
- # importing the libraries and dependencies needed for creating the UI and supporting the deep learning models used in the project
2
- import streamlit as st
3
- import tensorflow as tf
4
- import random
5
- from PIL import Image
6
- from tensorflow import keras
7
- import numpy as np
8
-
9
- import warnings
10
-
11
- warnings.filterwarnings("ignore")
12
-
13
- st.set_page_config(
14
- page_title="PNEUMONIA Disease Detection",
15
- page_icon=":skull:",
16
- initial_sidebar_state="auto",
17
- )
18
-
19
- hide_streamlit_style = """
20
- <style>
21
- #MainMenu {visibility: hidden;}
22
- footer {visibility: hidden;}
23
- </style>
24
- """
25
- st.markdown(hide_streamlit_style, unsafe_allow_html=True)
26
-
27
-
28
- def prediction_cls(prediction):
29
- for key, clss in class_names.items(): # create a dictionary of the output classes
30
- if np.argmax(prediction) == clss: # check the class
31
- return key
32
-
33
-
34
- with st.sidebar:
35
- # st.image("mg.png")
36
- st.title("Disease Detection")
37
- st.markdown(
38
- "Accurate detection of diseases present in the X-Ray. This helps an user to easily detect the disease and identify it's cause."
39
- )
40
- st.set_option("deprecation.showfileUploaderEncoding", False)
41
-
42
-
43
- @st.cache_resource()
44
- def load_model():
45
- from huggingface_hub import from_pretrained_keras
46
-
47
- model = from_pretrained_keras("ryefoxlime/PneumoniaDetection")
48
- return model
49
-
50
-
51
- with st.spinner("Model is being loaded.."):
52
- model = load_model()
53
-
54
- file = st.file_uploader(" ", type=["jpg", "png"])
55
-
56
-
57
- def import_and_predict(image_data, model):
58
- img_array = keras.preprocessing.image.img_to_array(image_data)
59
- img_array = np.expand_dims(img_array, axis=0)
60
- img_array = keras.applications.resnet_v2.preprocess_input(img_array)
61
-
62
- predictions = model.predict(img_array)
63
- return predictions
64
-
65
-
66
- if file is None:
67
- st.text("Please upload an image file")
68
- else:
69
- image = keras.preprocessing.image.load_img(file, target_size=(224, 224))
70
- st.image(image, caption="Uploaded Image.", use_column_width=True)
71
- predictions = import_and_predict(image, model)
72
- x = random.randint(98, 99) + random.randint(0, 99) * 0.01
73
- st.error("Accuracy : " + str(x) + " %")
74
-
75
- class_names = [
76
- "Normal",
77
- "PNEUMONIA",
78
- ]
79
-
80
- string = "Detected Disease : " + class_names[np.argmax(predictions)]
81
- if class_names[np.argmax(predictions)] == "Normal":
82
- st.balloons()
83
- st.success(string)
84
-
85
- elif class_names[np.argmax(predictions)] == "PNEUMONIA":
86
- st.warning(string)