Spaces:
Runtime error
Runtime error
Duplicate from dhhd255/parkinsons_docker
Browse filesCo-authored-by: Jay <[email protected]>
- .gitattributes +34 -0
- .streamlit/config.toml +10 -0
- Dockerfile +23 -0
- README.md +5 -0
- app.py +92 -0
- requirements.txt +6 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
.streamlit/config.toml
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[theme]
|
2 |
+
primaryColor="#e5ab00"
|
3 |
+
backgroundColor="#0e1117"
|
4 |
+
secondaryBackgroundColor="#282929"
|
5 |
+
textColor = "#ffffff"
|
6 |
+
font="sans serif"
|
7 |
+
|
8 |
+
[server]
|
9 |
+
maxUploadSize = 200
|
10 |
+
enableXsrfProtection = false
|
Dockerfile
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.8.9
|
2 |
+
|
3 |
+
WORKDIR /app
|
4 |
+
|
5 |
+
COPY ./requirements.txt /app/requirements.txt
|
6 |
+
COPY ./packages.txt /app/packages.txt
|
7 |
+
|
8 |
+
RUN apt-get update && xargs -r -a /app/packages.txt apt-get install -y && rm -rf /var/lib/apt/lists/*
|
9 |
+
RUN pip3 install --no-cache-dir -r /app/requirements.txt
|
10 |
+
|
11 |
+
# User
|
12 |
+
RUN useradd -m -u 1000 user
|
13 |
+
USER user
|
14 |
+
ENV HOME /home/user
|
15 |
+
ENV PATH $HOME/.local/bin:$PATH
|
16 |
+
|
17 |
+
WORKDIR $HOME
|
18 |
+
RUN mkdir app
|
19 |
+
WORKDIR $HOME/app
|
20 |
+
COPY . $HOME/app
|
21 |
+
|
22 |
+
EXPOSE 8501
|
23 |
+
CMD streamlit run app.py
|
README.md
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
sdk: docker
|
3 |
+
app_port: 8501
|
4 |
+
duplicated_from: dhhd255/parkinsons_docker
|
5 |
+
---
|
app.py
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from transformers import AutoModel
|
3 |
+
import torch.nn as nn
|
4 |
+
from PIL import Image
|
5 |
+
import numpy as np
|
6 |
+
import streamlit as st
|
7 |
+
|
8 |
+
# Set the device
|
9 |
+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
10 |
+
|
11 |
+
# Load the trained model from the Hugging Face Hub
|
12 |
+
model = AutoModel.from_pretrained('dhhd255/EfficientNet_ParkinsonsPred')
|
13 |
+
|
14 |
+
# Move the model to the device
|
15 |
+
model = model.to(device)
|
16 |
+
|
17 |
+
# Add custom CSS to use the Inter font, define custom classes for healthy and parkinsons results, increase the font size, make the text bold, and define the footer styles
|
18 |
+
st.markdown("""
|
19 |
+
<style>
|
20 |
+
@import url('https://fonts.googleapis.com/css2?family=Inter&display=swap');
|
21 |
+
body {
|
22 |
+
font-family: 'Inter', sans-serif;
|
23 |
+
}
|
24 |
+
.result {
|
25 |
+
font-size: 24px;
|
26 |
+
font-weight: bold;
|
27 |
+
}
|
28 |
+
.healthy {
|
29 |
+
color: #007E3F;
|
30 |
+
}
|
31 |
+
.parkinsons {
|
32 |
+
color: #C30000;
|
33 |
+
}
|
34 |
+
.social-links {
|
35 |
+
display: flex;
|
36 |
+
text-decoration:none;
|
37 |
+
justify-content: center;
|
38 |
+
}
|
39 |
+
.social-links a {
|
40 |
+
text-decoration:none;
|
41 |
+
padding: 0 10px;
|
42 |
+
}
|
43 |
+
</style>
|
44 |
+
""", unsafe_allow_html=True)
|
45 |
+
|
46 |
+
st.title("Parkinson's Disease Prediction")
|
47 |
+
|
48 |
+
uploaded_file = st.file_uploader("Upload your :blue[Spiral] drawing here", type=["png", "jpg", "jpeg"])
|
49 |
+
st.empty()
|
50 |
+
if uploaded_file is not None:
|
51 |
+
col1, col2 = st.columns(2)
|
52 |
+
|
53 |
+
# Load and resize the image
|
54 |
+
image_size = (224, 224)
|
55 |
+
new_image = Image.open(uploaded_file).convert('RGB').resize(image_size)
|
56 |
+
col1.image(new_image, width=255)
|
57 |
+
new_image = np.array(new_image)
|
58 |
+
new_image = torch.from_numpy(new_image).transpose(0, 2).float().unsqueeze(0)
|
59 |
+
|
60 |
+
# Move the data to the device
|
61 |
+
new_image = new_image.to(device)
|
62 |
+
|
63 |
+
# Make predictions using the trained model
|
64 |
+
with torch.no_grad():
|
65 |
+
predictions = model(new_image)
|
66 |
+
logits = predictions.last_hidden_state
|
67 |
+
logits = logits.view(logits.shape[0], -1)
|
68 |
+
num_classes=2
|
69 |
+
feature_reducer = nn.Linear(logits.shape[1], num_classes)
|
70 |
+
|
71 |
+
logits = logits.to(device)
|
72 |
+
feature_reducer = feature_reducer.to(device)
|
73 |
+
|
74 |
+
logits = feature_reducer(logits)
|
75 |
+
predicted_class = torch.argmax(logits, dim=1).item()
|
76 |
+
confidence = torch.softmax(logits, dim=1)[0][predicted_class].item()
|
77 |
+
if(predicted_class == 0):
|
78 |
+
col2.markdown('<span class="result parkinsons">Predicted class: Parkinson\'s</span>', unsafe_allow_html=True)
|
79 |
+
col2.caption(f'{confidence*100:.0f}% sure')
|
80 |
+
else:
|
81 |
+
col2.markdown('<span class="result healthy">Predicted class: Healthy</span>', unsafe_allow_html=True)
|
82 |
+
col2.caption(f'{confidence*100:.0f}% sure')
|
83 |
+
|
84 |
+
uploaded_file = st.file_uploader("Upload your :blue[Wave] drawing here", type=["png", "jpg", "jpeg"])
|
85 |
+
st.divider()
|
86 |
+
st.markdown("""
|
87 |
+
<div class="social-links">
|
88 |
+
<a href="https://twitter.com/your_twitter_handle">Twitter</a>
|
89 |
+
<a href="https://facebook.com/your_facebook_page">Facebook</a>
|
90 |
+
<a href="https://instagram.com/your_instagram_handle">Instagram</a>
|
91 |
+
</div>
|
92 |
+
""", unsafe_allow_html=True)
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
numpy
|
3 |
+
pandas
|
4 |
+
pillow
|
5 |
+
torch
|
6 |
+
transformers
|