oliverlibaw commited on
Commit
79efff5
1 Parent(s): 65d78c0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tensorflow as tf
2
+ import cv2
3
+ import numpy as np
4
+ from glob import glob
5
+ # from models import Yolov4
6
+ import gradio as gr
7
+ # model = Yolov4(weight_path="best.pt", class_name_path='coco_classes.txt')
8
+
9
+
10
+ from ultralytics import YOLO
11
+
12
+ # Load a model
13
+ model = YOLO("best.pt") # load a custom model
14
+
15
+ # Predict with the model
16
+ # results = model("image.jpg", save = True) # predict on an image
17
+
18
+
19
+ def gradio_wrapper(img):
20
+ global model
21
+ #print(np.shape(img))
22
+ results = model.predict(img) # predict on an image
23
+ try:
24
+ if max(results[0].boxes.cls) == 0:
25
+ text = "Man"
26
+ if max(results[0].boxes.cls) == 1:
27
+ text = "Women"
28
+ except:
29
+ pass
30
+
31
+ return cv2.putText(img, text,(00, 185), cv2.FONT_HERSHEY_SIMPLEX, 1,
32
+ (0, 0, 255), 2, cv2.LINE_AA, False)
33
+ # return results
34
+
35
+ demo = gr.Interface(
36
+ gradio_wrapper,
37
+ #gr.Image(source="webcam", streaming=True, flip=True),
38
+ gr.Image(source="webcam", streaming=True),
39
+ "image",
40
+ live=True
41
+ )
42
+
43
+ demo.launch()