Mahimai Raja J
commited on
Commit
β’
f747692
1
Parent(s):
0a60ba3
Initial Release
Browse files- .gitignore +11 -0
- app.py +84 -0
- model.pth +3 -0
- modules.py +48 -0
- requirements.txt +2 -0
.gitignore
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Virtualenv
|
2 |
+
env
|
3 |
+
|
4 |
+
# Cache
|
5 |
+
__pycache__
|
6 |
+
|
7 |
+
# Mac OS X
|
8 |
+
.DS_Store
|
9 |
+
|
10 |
+
# file upload
|
11 |
+
data
|
app.py
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from PIL import Image
|
3 |
+
import os
|
4 |
+
import cv2
|
5 |
+
from modules import *
|
6 |
+
|
7 |
+
|
8 |
+
def processImage():
|
9 |
+
"""
|
10 |
+
UI Part if the users chooses
|
11 |
+
to proceess a image.
|
12 |
+
"""
|
13 |
+
# load the model
|
14 |
+
model = setup()
|
15 |
+
# load the image
|
16 |
+
image_file = st.file_uploader("Upload An Image",type=['png','jpeg','jpg'])
|
17 |
+
# check if the image is uploaded
|
18 |
+
if image_file is not None:
|
19 |
+
# get the file details
|
20 |
+
file_details = {"FileName":image_file.name,"FileType":image_file.type}
|
21 |
+
file_type = (image_file.type).split('/')[1]
|
22 |
+
# make a directory to store the image
|
23 |
+
if not os.path.exists(os.path.join(os.getcwd(),"data")):
|
24 |
+
os.makedirs(os.path.join(os.getcwd(),"data"))
|
25 |
+
# save the image
|
26 |
+
input_file_name = f"data/Input.{file_type}"
|
27 |
+
with open(input_file_name,mode = "wb") as f:
|
28 |
+
f.write(image_file.getbuffer())
|
29 |
+
# predict the image and save it
|
30 |
+
result_frame, labels = predict(input_file_name,model)
|
31 |
+
cv2.imwrite('data/result.jpg', result_frame)
|
32 |
+
# display the image and class
|
33 |
+
img_ = Image.open(f"data/result.jpg")
|
34 |
+
result_class = list(labels).split(" ")[0]
|
35 |
+
confidence = float(list(labels).split(" ")[1])
|
36 |
+
|
37 |
+
st.subheader(f"Result {result_class} with confidence {confidence * 100 :.2f}%")
|
38 |
+
st.image(img_)
|
39 |
+
# To download the image
|
40 |
+
with open("data/result.jpg", "rb") as file:
|
41 |
+
st.download_button(
|
42 |
+
label="Download image",
|
43 |
+
data=file,
|
44 |
+
file_name="predicted.jpg",
|
45 |
+
mime="image/jpg"
|
46 |
+
)
|
47 |
+
|
48 |
+
|
49 |
+
def main():
|
50 |
+
"""
|
51 |
+
UI Part of the entire application.
|
52 |
+
"""
|
53 |
+
st.set_page_config(
|
54 |
+
page_title ="Parkinson-X",
|
55 |
+
page_icon = "π§",
|
56 |
+
menu_items={
|
57 |
+
'About': "# Parkinson's Prediction"
|
58 |
+
}
|
59 |
+
)
|
60 |
+
st.markdown("<h1 style='text-align: center;'>Parkinson's <span style='color: #9eeade;'>Prediction</span></h1>", unsafe_allow_html=True)
|
61 |
+
st.subheader("Early Parkinson's detection")
|
62 |
+
|
63 |
+
st.title('Drawing Analysis')
|
64 |
+
|
65 |
+
processImage()
|
66 |
+
with st.expander("Parkinson's Prediction"):
|
67 |
+
st.markdown( "<p style='font-size: 30px;'><strong>Welcome to the Parkinson's \
|
68 |
+
<span style='color: #9eeade;'>Prediction</span> App!</strong></p>", unsafe_allow_html= True)
|
69 |
+
st.markdown("<p style = 'font-size : 20px; color : white;'>This application was \
|
70 |
+
built to analyse the <strong>spiral drawings</strong> \
|
71 |
+
to predict and suggest parkinson diagnosis.</p>", unsafe_allow_html=True)
|
72 |
+
|
73 |
+
if __name__ == '__main__':
|
74 |
+
__author__ = 'Mahimai Raja J'
|
75 |
+
__version__ = "1.0.0"
|
76 |
+
main()
|
77 |
+
|
78 |
+
# π NOTE :
|
79 |
+
# Do not modify the credits unless you have
|
80 |
+
# legal permission from the authorizing authority .
|
81 |
+
|
82 |
+
# Thank you for helping to maintain the integrity of the
|
83 |
+
# open source community by promoting fair and ethical
|
84 |
+
# use of open source software π.
|
model.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:05894076416648b190ae699ae5de8142dfe4bb0b634bfdb8fa08dcb58b2fd6ab
|
3 |
+
size 892867872
|
modules.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from super_gradients.training import models
|
2 |
+
import supervision as sv
|
3 |
+
import torch
|
4 |
+
import cv2
|
5 |
+
|
6 |
+
# install the required packages
|
7 |
+
# pip install -q super-gradients==3.1.1 supervision
|
8 |
+
|
9 |
+
# predict function to predict the image
|
10 |
+
def predict(img, model):
|
11 |
+
SOURCE_IMAGE_PATH = img
|
12 |
+
image = cv2.imread(SOURCE_IMAGE_PATH)
|
13 |
+
result = list(model.predict(image, conf=0.70))[0]
|
14 |
+
detections = sv.Detections(
|
15 |
+
xyxy=result.prediction.bboxes_xyxy,
|
16 |
+
confidence=result.prediction.confidence,
|
17 |
+
class_id=result.prediction.labels.astype(int)
|
18 |
+
)
|
19 |
+
# Create a box annotator
|
20 |
+
box_annotator = sv.BoxAnnotator()
|
21 |
+
# Get the labels
|
22 |
+
labels = [
|
23 |
+
f"{result.class_names[class_id]} {confidence:0.2f}"
|
24 |
+
for _, _, confidence, class_id, _
|
25 |
+
in detections
|
26 |
+
]
|
27 |
+
# Annotate the image
|
28 |
+
annotated_frame = box_annotator.annotate(
|
29 |
+
scene=image.copy(),
|
30 |
+
detections=detections,
|
31 |
+
labels=labels
|
32 |
+
)
|
33 |
+
|
34 |
+
# sv.plot_image(annotated_frame, (12, 12))
|
35 |
+
return annotated_frame, labels
|
36 |
+
|
37 |
+
|
38 |
+
def setup():
|
39 |
+
DEVICE = 'cuda' if torch.cuda.is_available() else "cpu" # 'cpu' or 'cuda'
|
40 |
+
MODEL_ARCH = 'yolo_nas_l'
|
41 |
+
|
42 |
+
# Load the model
|
43 |
+
model = models.get(
|
44 |
+
MODEL_ARCH,
|
45 |
+
num_classes=2,
|
46 |
+
checkpoint_path="model.pth"
|
47 |
+
).to(DEVICE)
|
48 |
+
return model
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
super-gradients==3.1.1
|
2 |
+
supervision==0.8.0
|