calmdowngirl commited on
Commit
8ce1df4
·
1 Parent(s): 870e9a7

display title

Browse files
__pycache__/ppl_detector.cpython-312.pyc CHANGED
Binary files a/__pycache__/ppl_detector.cpython-312.pyc and b/__pycache__/ppl_detector.cpython-312.pyc differ
 
app.py CHANGED
@@ -1,11 +1,15 @@
1
  import gradio as gr
2
 
3
- from ppl_detector import detect
4
 
5
  with gr.Blocks() as demo:
6
- img_input = gr.Image(type="filepath", label="Input Image")
 
 
 
7
  img_output = gr.Image(label="Output Image with Detections")
8
 
9
  img_input.change(fn=detect, inputs=img_input, outputs=img_output)
 
10
 
11
  demo.launch()
 
1
  import gradio as gr
2
 
3
+ from ppl_detector import detect, set_result
4
 
5
  with gr.Blocks() as demo:
6
+ img_input = gr.Image(type="filepath", format="jpg", label="Input Image")
7
+
8
+ title = "<h1 id='result' style='display: flex;justify-content: center;'>it counts ppl, upload an image, see how it goes</h1>"
9
+ state = gr.HTML(title)
10
  img_output = gr.Image(label="Output Image with Detections")
11
 
12
  img_input.change(fn=detect, inputs=img_input, outputs=img_output)
13
+ img_output.change(fn=set_result, outputs=state)
14
 
15
  demo.launch()
ppl_detector.py CHANGED
@@ -1,9 +1,10 @@
1
  from transformers import pipeline
2
-
3
  from PIL import Image, ImageDraw
 
4
 
5
  detector = pipeline("object-detection", model="hustvl/yolos-base")
6
  source = None
 
7
 
8
  def draw_bbox(bboxes):
9
  global source
@@ -15,24 +16,34 @@ def draw_bbox(bboxes):
15
 
16
 
17
  def detect(img):
18
- global source
19
- if source is None and img is not None:
20
  source = Image.open(img)
21
  else:
22
  return None
23
 
 
 
24
  objects = detector(source)
25
  persons = [
26
  o for o in objects
27
  if o['label'] == 'person' and o['score'] > 0.83]
28
  bboxes = list(map(lambda p: (p['box']['xmin'], p['box']['ymin'], p['box']['xmax'], p['box']['ymax']), persons))
29
  n = len(persons)
30
-
31
- print(f"it's got {n} {'ppl' if n > 1 else 'person'} in the image")
32
 
33
  draw_bbox(bboxes)
34
  return source
35
 
 
 
 
 
 
 
 
 
 
36
 
37
 
38
 
 
1
  from transformers import pipeline
 
2
  from PIL import Image, ImageDraw
3
+ from pprint import pprint
4
 
5
  detector = pipeline("object-detection", model="hustvl/yolos-base")
6
  source = None
7
+ state = None
8
 
9
  def draw_bbox(bboxes):
10
  global source
 
16
 
17
 
18
  def detect(img):
19
+ global source, result
20
+ if img is not None:
21
  source = Image.open(img)
22
  else:
23
  return None
24
 
25
+ print("processing img...")
26
+
27
  objects = detector(source)
28
  persons = [
29
  o for o in objects
30
  if o['label'] == 'person' and o['score'] > 0.83]
31
  bboxes = list(map(lambda p: (p['box']['xmin'], p['box']['ymin'], p['box']['xmax'], p['box']['ymax']), persons))
32
  n = len(persons)
33
+ result = f"it's got {n} {'ppl' if n > 1 else 'person'} in the image"
 
34
 
35
  draw_bbox(bboxes)
36
  return source
37
 
38
+ def set_result(*args):
39
+ global result
40
+ if result is None:
41
+ return f"<h1 id='result' style='display: flex;justify-content: center;'>it counts ppl, upload an image, see how it goes</h1>"
42
+ else:
43
+ title = f"<h1 id='result' style='display: flex;justify-content: center;'>{result}</h1>"
44
+ result = None
45
+ return title
46
+
47
 
48
 
49