Spaces:
Sleeping
Sleeping
Pankaj Munde
commited on
Commit
β’
88e182d
1
Parent(s):
dc0ac35
Added Credentials
Browse files- .gitignore +1 -0
- app.py +77 -61
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
.vscode
|
app.py
CHANGED
@@ -2,6 +2,9 @@ import os
|
|
2 |
import base64
|
3 |
import streamlit as st
|
4 |
from streamlit_option_menu import option_menu
|
|
|
|
|
|
|
5 |
import pandas as pd
|
6 |
from PIL import Image
|
7 |
|
@@ -16,11 +19,27 @@ from glob import glob
|
|
16 |
|
17 |
MODEL_PATH = "pankaj-munde/FScout_v0.2"
|
18 |
# image_dir = "./Data/images/"
|
19 |
-
detr_preprocessor = AutoImageProcessor.from_pretrained(MODEL_PATH)
|
20 |
-
detr_model = AutoModelForObjectDetection.from_pretrained(MODEL_PATH)
|
21 |
colors = [[236, 112, 99], [165, 105, 189], [ 225, 9, 232], [ 255, 38, 8 ], [ 247, 249, 249 ], [170, 183, 184 ], [ 247, 249, 249 ], [ 247, 249, 249 ]]
|
22 |
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
# images_lst = os.listdir(image_dir)
|
25 |
# images = []
|
26 |
# for file in images_lst:
|
@@ -154,11 +173,6 @@ def image_checkup_v4(ipath, thresh, show_count):
|
|
154 |
return [], img_with_box
|
155 |
|
156 |
|
157 |
-
|
158 |
-
st.set_page_config(layout="wide")
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
def add_logo(logo_path, width, height):
|
163 |
"""Read and return a resized logo"""
|
164 |
logo = Image.open(logo_path)
|
@@ -167,62 +181,64 @@ def add_logo(logo_path, width, height):
|
|
167 |
|
168 |
|
169 |
# st.write("<hr/>", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
st.image
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
st.
|
180 |
-
st.write("
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
st.write("
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
|
|
|
|
|
|
|
|
208 |
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
</div>
|
215 |
-
"""
|
216 |
-
|
217 |
-
st.markdown(html_string, unsafe_allow_html=True)
|
218 |
-
|
219 |
-
st.write("<hr/>", unsafe_allow_html=True)
|
220 |
-
|
221 |
-
with col1:
|
222 |
-
st.subheader("π Predicted Image")
|
223 |
-
st.write("<br/>", unsafe_allow_html=True)
|
224 |
-
|
225 |
-
st.image(result_image)
|
226 |
|
227 |
|
228 |
|
|
|
2 |
import base64
|
3 |
import streamlit as st
|
4 |
from streamlit_option_menu import option_menu
|
5 |
+
from streamlit_authenticator import Authenticate
|
6 |
+
import yaml
|
7 |
+
from yaml.loader import SafeLoader
|
8 |
import pandas as pd
|
9 |
from PIL import Image
|
10 |
|
|
|
19 |
|
20 |
MODEL_PATH = "pankaj-munde/FScout_v0.2"
|
21 |
# image_dir = "./Data/images/"
|
22 |
+
detr_preprocessor = AutoImageProcessor.from_pretrained(MODEL_PATH, token=st.secrets["HF_TOKEN"])
|
23 |
+
detr_model = AutoModelForObjectDetection.from_pretrained(MODEL_PATH, token=st.secrets["HF_TOKEN"])
|
24 |
colors = [[236, 112, 99], [165, 105, 189], [ 225, 9, 232], [ 255, 38, 8 ], [ 247, 249, 249 ], [170, 183, 184 ], [ 247, 249, 249 ], [ 247, 249, 249 ]]
|
25 |
|
26 |
|
27 |
+
# with open('./static/config.yaml') as file:
|
28 |
+
# config = yaml.load(file, Loader=SafeLoader)
|
29 |
+
|
30 |
+
config = {"credentials": st.secrets["CREDENTIALS"], "cookie": st.secrets["COOKIE"]}
|
31 |
+
|
32 |
+
authenticator = Authenticate(
|
33 |
+
config['credentials'],
|
34 |
+
config['cookie']['name'],
|
35 |
+
config['cookie']['key'],
|
36 |
+
config['cookie']['expiry_days'],
|
37 |
+
config['preauthorized']
|
38 |
+
)
|
39 |
+
|
40 |
+
|
41 |
+
name, authentication_status, username = authenticator.login('Login', 'main')
|
42 |
+
|
43 |
# images_lst = os.listdir(image_dir)
|
44 |
# images = []
|
45 |
# for file in images_lst:
|
|
|
173 |
return [], img_with_box
|
174 |
|
175 |
|
|
|
|
|
|
|
|
|
|
|
176 |
def add_logo(logo_path, width, height):
|
177 |
"""Read and return a resized logo"""
|
178 |
logo = Image.open(logo_path)
|
|
|
181 |
|
182 |
|
183 |
# st.write("<hr/>", unsafe_allow_html=True)
|
184 |
+
if st.session_state["authentication_status"]:
|
185 |
+
with st.sidebar:
|
186 |
+
my_logo = add_logo(logo_path="./static//FarmGyan logo_1.png", width=50, height=60)
|
187 |
+
st.image(my_logo)
|
188 |
+
ucol, bcol = st.columns([3, 2])
|
189 |
+
ucol.write(f'## Welcome *{st.session_state["name"]}*')
|
190 |
+
with bcol:
|
191 |
+
authenticator.logout('Logout', 'main')
|
192 |
+
|
193 |
+
st.write("<hr/>", unsafe_allow_html=True)
|
194 |
|
195 |
+
st.title(":seedling: FarmGyan | Insects Scouting")
|
196 |
+
st.write("<hr/>", unsafe_allow_html=True)
|
197 |
+
|
198 |
+
st.write("## π Upload image for prediction")
|
199 |
+
|
200 |
+
uploaded_file = st.file_uploader("Choose an image file", type=["jpg", "jpeg", "png"])
|
201 |
+
st.write("<hr/>", unsafe_allow_html=True)
|
202 |
+
|
203 |
+
with st.spinner(text='In progress'):
|
204 |
+
st.sidebar.write("## βοΈ Configurations")
|
205 |
+
st.sidebar.write("<hr/>", unsafe_allow_html=True)
|
206 |
+
|
207 |
+
st.sidebar.write("#### Prediction Threshold")
|
208 |
+
thresh = st.sidebar.slider("Threshold", 0.0, 1.0, 0.7, 0.1)
|
209 |
+
st.sidebar.write("#### Boxes Count")
|
210 |
+
show_count = st.sidebar.checkbox("Show Count")
|
211 |
+
if uploaded_file is not None:
|
212 |
+
clicked = None
|
213 |
+
image = Image.open(uploaded_file).convert("RGB")
|
214 |
+
predicted_data, result_image = image_checkup_v4(image, thresh, show_count)
|
215 |
+
# print(predicted_data)
|
216 |
+
|
217 |
+
col, col1 = st.columns([2, 4])
|
218 |
+
feedback_submitted = False # Initialize the flag
|
219 |
+
with col:
|
220 |
+
st.subheader("π― Predicted Labels")
|
221 |
+
st.write(f"<h3>Total Count : {sum([d['Count'] for d in predicted_data])}</h3>", unsafe_allow_html=True)
|
222 |
+
for i, d in enumerate(predicted_data):
|
223 |
+
# Create HTML markup with style information
|
224 |
+
|
225 |
+
html_string = f"""
|
226 |
+
<div style="display: flex; align-items: center;">
|
227 |
+
<b style="margin-right: 15px">{i + 1}. </b>
|
228 |
+
<div style="background-color: rgb({d["Color"][0]}, {d["Color"][1]}, {d["Color"][2]}); width: 20px; height: 20px; border: 1px solid black; margin-right: 10px;"></div>
|
229 |
+
<p style="margin-top: 15px"><b>{d["Insect"]} : {d["Count"]} </b></p>
|
230 |
+
</div>
|
231 |
+
"""
|
232 |
+
|
233 |
+
st.markdown(html_string, unsafe_allow_html=True)
|
234 |
+
|
235 |
+
st.write("<hr/>", unsafe_allow_html=True)
|
236 |
|
237 |
+
with col1:
|
238 |
+
st.subheader("π Predicted Image")
|
239 |
+
st.write("<br/>", unsafe_allow_html=True)
|
240 |
+
|
241 |
+
st.image(result_image)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
242 |
|
243 |
|
244 |
|