Sibaprasad commited on
Commit
ce07712
·
1 Parent(s): ffd7146

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -4
app.py CHANGED
@@ -1,12 +1,12 @@
1
  import os
2
  import streamlit as st
 
3
  # from transformers import pipeline
4
  from PIL import Image
5
-
6
  # pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
7
 
8
 
9
-
10
  st.title("Helmet Detection App: ⛑")
11
  confidence=st.slider("Confidence score (0-0.9)",
12
  min_value=0.0,
@@ -15,8 +15,12 @@ confidence=st.slider("Confidence score (0-0.9)",
15
  step=.1)
16
  file_name = st.file_uploader("Upload an image where workers may or may not wear helmets.")
17
 
18
- if file_name is not None:
19
  col1, col2 = st.columns(2)
 
 
 
 
20
 
21
  image = Image.open(file_name)
22
  image.save("data/inputImg.jpg")
@@ -29,4 +33,31 @@ if file_name is not None:
29
  os.system("rm -rf yolov5/runs")
30
  col2.image(output, use_column_width=True)
31
  image.close()
32
- output.close()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
  import streamlit as st
3
+ import base64
4
  # from transformers import pipeline
5
  from PIL import Image
6
+ from st_clickable_images import clickable_images
7
  # pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
8
 
9
 
 
10
  st.title("Helmet Detection App: ⛑")
11
  confidence=st.slider("Confidence score (0-0.9)",
12
  min_value=0.0,
 
15
  step=.1)
16
  file_name = st.file_uploader("Upload an image where workers may or may not wear helmets.")
17
 
18
+ if (file_name is not None):
19
  col1, col2 = st.columns(2)
20
+ # img1 =""
21
+ # img2 =""
22
+ # col1.image(img1, use_column_width=True)
23
+ # col2.image(img2, use_column_width=True)
24
 
25
  image = Image.open(file_name)
26
  image.save("data/inputImg.jpg")
 
33
  os.system("rm -rf yolov5/runs")
34
  col2.image(output, use_column_width=True)
35
  image.close()
36
+ output.close()
37
+
38
+ elif (st.checkbox('Select an example by clicking on the checkbox.')):
39
+ image_list=["https://media.istockphoto.com/id/1301722993/photo/group-of-contractors-celebrating-the-end-of-successful-construction-process.jpg?s=612x612&w=0&k=20&c=Xv7sO0AGHITZ6-SdTFrvXYnlWQ_Sc3wAcnGory4n1NA=","https://media.istockphoto.com/id/1472264590/photo/substation-maintenance-engineers.webp?b=1&s=170667a&w=0&k=20&c=dXhPK_sakEhOsAFb6InX4onVoaSgmUZ5A-V6eUlZf8E="]
40
+ # st.markdown("select a image")
41
+ clicked = clickable_images(
42
+ image_list,
43
+ titles=[f"Image #{str(i)}" for i in range(len(image_list))],
44
+ div_style={"display": "flex", "justify-content": "space-between", "flex-wrap": "wrap"},
45
+ img_style={"margin": "5px", "height": "200px"},
46
+ key=None,
47
+ )
48
+ st.markdown(f"Image # {clicked} selected" if clicked > -1 else "No image selected")
49
+ if clicked>-1:
50
+ col1, col2 = st.columns(2)
51
+ file_exp =f"sample/image{clicked+1}.jpg"
52
+ image = Image.open(file_exp)
53
+ image.save("data/inputImg.jpg")
54
+ col1.image(image, use_column_width=True)
55
+ os.system(f"cd yolov5/ && python detect.py --weights ../best.pt --img 416 --conf {confidence} --source ../data/inputImg.jpg")
56
+ im = Image.open("yolov5/runs/detect/exp/inputImg.jpg")
57
+ im.save("data/output.jpg")
58
+ im.close()
59
+ output =Image.open("data/output.jpg")
60
+ col2.image(output, use_column_width=True)
61
+ image.close()
62
+ output.close()
63
+ os.system("rm -rf yolov5/runs")