sergioska commited on
Commit
2899d04
·
1 Parent(s): df9e0ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -1
app.py CHANGED
@@ -3,9 +3,11 @@ import glob
3
  import torch
4
  import streamlit as st
5
  import numpy as np
 
6
  from PIL import Image, ImageDraw
7
  from transformers import pipeline
8
  from tempfile import NamedTemporaryFile
 
9
 
10
  st.set_page_config(layout="wide")
11
 
@@ -16,6 +18,7 @@ st.title('Upload an image file to detection')
16
  col1, col2, col3 = st.columns([0.5, 0.3, 0.2])
17
 
18
  gibsOk = False
 
19
  with col1:
20
 
21
  st.header('flyer')
@@ -54,6 +57,7 @@ with col1:
54
  cv2.imwrite("/tmp/cropped_image_{}.jpg".format(i), crop_img)
55
  i += 1
56
 
 
57
  gibsOk = True
58
  imageLocation.image(image)
59
  st.write(predictions)
@@ -62,5 +66,15 @@ with col2:
62
  st.header('gibs')
63
  images = []
64
  for cropped in glob.glob('/tmp/cropped_image_*'):
65
- st.write(cropped)
 
 
 
 
 
 
 
 
 
 
66
 
 
3
  import torch
4
  import streamlit as st
5
  import numpy as np
6
+ import base64
7
  from PIL import Image, ImageDraw
8
  from transformers import pipeline
9
  from tempfile import NamedTemporaryFile
10
+ from st_clickable_images import clickable_images
11
 
12
  st.set_page_config(layout="wide")
13
 
 
18
  col1, col2, col3 = st.columns([0.5, 0.3, 0.2])
19
 
20
  gibsOk = False
21
+ totalGibs = 0
22
  with col1:
23
 
24
  st.header('flyer')
 
57
  cv2.imwrite("/tmp/cropped_image_{}.jpg".format(i), crop_img)
58
  i += 1
59
 
60
+ totalGibs = i
61
  gibsOk = True
62
  imageLocation.image(image)
63
  st.write(predictions)
 
66
  st.header('gibs')
67
  images = []
68
  for cropped in glob.glob('/tmp/cropped_image_*'):
69
+ with open(cropped, "rb") as image:
70
+ encoded = base64.b64encode(image.read()).decode()
71
+ images.append(f"data:image/jpeg;base64,{encoded}")
72
+ clicked = clickable_images(
73
+ images,
74
+ titles=[f"Image #{str(i)}" for i in range(totalGibs)],
75
+ div_style={"display": "flex", "justify-content": "center", "flex-wrap": "wrap"},
76
+ img_style={"margin": "5px", "height": "150px"},
77
+ )
78
+
79
+ st.markdown(f"Image #{clicked} clicked" if clicked > -1 else "No image clicked")
80