|
import streamlit as st |
|
from PIL import Image |
|
import os |
|
import cv2 |
|
from modules import * |
|
|
|
|
|
def processImage(): |
|
""" |
|
UI Part if the users chooses |
|
to proceess a image. |
|
""" |
|
|
|
model = setup() |
|
|
|
image_file = st.file_uploader("Upload An Image",type=['png','jpeg','jpg']) |
|
|
|
if image_file is not None: |
|
|
|
file_details = {"FileName":image_file.name,"FileType":image_file.type} |
|
file_type = (image_file.type).split('/')[1] |
|
|
|
if not os.path.exists(os.path.join(os.getcwd(),"data")): |
|
os.makedirs(os.path.join(os.getcwd(),"data")) |
|
|
|
input_file_name = f"data/Input.{file_type}" |
|
with open(input_file_name,mode = "wb") as f: |
|
f.write(image_file.getbuffer()) |
|
|
|
result_frame, labels = predict(input_file_name,model) |
|
cv2.imwrite('data/result.jpg', result_frame) |
|
|
|
img_ = Image.open(f"data/result.jpg") |
|
result_class = " ".join(labels).split()[0] |
|
confidence = float(" ".join(labels).split()[1]) |
|
|
|
st.subheader(f"Result {result_class} with confidence {confidence * 100 :.2f}%") |
|
st.image(img_) |
|
|
|
with open("data/result.jpg", "rb") as file: |
|
st.download_button( |
|
label="Download image", |
|
data=file, |
|
file_name="predicted.jpg", |
|
mime="image/jpg" |
|
) |
|
|
|
|
|
def main(): |
|
""" |
|
UI Part of the entire application. |
|
""" |
|
st.set_page_config( |
|
page_title ="Parkinson-X", |
|
page_icon = "π§", |
|
menu_items={ |
|
'About': "# Parkinson's Prediction" |
|
} |
|
) |
|
st.markdown("<h1 style='text-align: center;'>Parkinson's <span style='color: #9eeade;'>Prediction</span></h1>", unsafe_allow_html=True) |
|
st.subheader("Early Parkinson's detection") |
|
|
|
st.title('Drawing Analysis') |
|
|
|
processImage() |
|
with st.expander("Parkinson's Prediction"): |
|
st.markdown( "<p style='font-size: 30px;'><strong>Welcome to the Parkinson's \ |
|
<span style='color: #9eeade;'>Prediction</span> App!</strong></p>", unsafe_allow_html= True) |
|
st.markdown("<p style = 'font-size : 20px; color : white;'>This application was \ |
|
built to analyse the <strong>spiral drawings</strong> \ |
|
to predict and suggest parkinson diagnosis.</p>", unsafe_allow_html=True) |
|
|
|
if __name__ == '__main__': |
|
__author__ = 'Mahimai Raja J' |
|
__version__ = "1.0.0" |
|
main() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|