BrunoMelicio commited on
Commit
46845d8
·
1 Parent(s): ab1609a

Added mediapipe functions and model

Browse files
Files changed (3) hide show
  1. app.py +23 -2
  2. efficientdet_lite0.tflite +3 -0
  3. requirements.txt +2 -1
app.py CHANGED
@@ -1,10 +1,31 @@
1
  import gradio as gr
2
- #import mediapipe as mp
3
  #from mediapipe.tasks import python
4
  #from mediapipe.tasks.python import vision
5
 
 
 
 
 
 
6
  def analyze_image(image):
7
- return image.name
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  img = gr.Image()
10
  txt = gr.Text()
 
1
  import gradio as gr
2
+ import mediapipe as mp
3
  #from mediapipe.tasks import python
4
  #from mediapipe.tasks.python import vision
5
 
6
+ BaseOptions = mp.tasks.BaseOptions
7
+ ObjectDetector = mp.tasks.vision.ObjectDetector
8
+ ObjectDetectorOptions = mp.tasks.vision.ObjectDetectorOptions
9
+ VisionRunningMode = mp.tasks.vision.RunningMode
10
+
11
  def analyze_image(image):
12
+ model_path = "efficientdet_lite0.tflite"
13
+
14
+ options = ObjectDetectorOptions(
15
+ base_options=BaseOptions(model_asset_path=model_path),
16
+ max_results=1,
17
+ running_mode=VisionRunningMode.IMAGE)
18
+
19
+ mp_image = mp.Image(image_format=mp.ImageFormat.SRGB, data=image)
20
+
21
+ with ObjectDetector.create_from_options(options) as detector:
22
+ detection_result = detector.detect(mp_image)
23
+
24
+ results = ""
25
+ for i,detection in enumerate(detection_result.detections):
26
+ text += f'Detection {i}: {detection.categories[0].category_name}\n'
27
+
28
+ return results
29
 
30
  img = gr.Image()
31
  txt = gr.Text()
efficientdet_lite0.tflite ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0720bf247bd76e6594ea28fa9c6f7c5242be774818997dbbeffc4da460c723bb
3
+ size 4602795
requirements.txt CHANGED
@@ -1 +1,2 @@
1
- numpy
 
 
1
+ numpy
2
+ mediapipe