Sa-m commited on
Commit
b15ad93
·
1 Parent(s): 2aef184

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -5
app.py CHANGED
@@ -16,10 +16,10 @@ app = Flask(__name__)
16
  DETECTION_URL = "/v1/detect"
17
 
18
 
19
- @app.route('/',methods=["POST"])
20
  def predict():
21
 
22
- model = torch.hub.load('ultralytics/yolov5', 'custom', path='best2.pt', force_reload=True) # force_reload to recache
23
 
24
  '''if not request.method == "POST":
25
  return'''
@@ -31,11 +31,20 @@ def predict():
31
  img = Image.open(io.BytesIO(image_bytes))
32
 
33
  results = model(img, size=640) # reduce size=320 for faster inference
34
- return results.pandas().xyxy[0].to_json(orient="records")
35
-
36
 
 
37
  if __name__ == "__main__":
38
 
39
- subprocess.run(["export","FLASK_ENV","=","development"])
40
  app.run(host="0.0.0.0", port=7860) # debug=True causes Restarting with stat
41
  #serve(app, host="0.0.0.0", port=7860)
 
 
 
 
 
 
 
 
 
16
  DETECTION_URL = "/v1/detect"
17
 
18
 
19
+ @app.route(DETECTION_URL,methods=["POST"])
20
  def predict():
21
 
22
+ #model = torch.hub.load('ultralytics/yolov5', 'custom', path='best2.pt', force_reload=True) # force_reload to recache
23
 
24
  '''if not request.method == "POST":
25
  return'''
 
31
  img = Image.open(io.BytesIO(image_bytes))
32
 
33
  results = model(img, size=640) # reduce size=320 for faster inference
34
+ results=results.pandas().xyxy[0].to_json(orient="records")
35
+ return f"{results}"
36
 
37
+ '''
38
  if __name__ == "__main__":
39
 
40
+ #subprocess.run(["export","FLASK_ENV","=","development"])
41
  app.run(host="0.0.0.0", port=7860) # debug=True causes Restarting with stat
42
  #serve(app, host="0.0.0.0", port=7860)
43
+ '''
44
+ if __name__ == "__main__":
45
+ parser = argparse.ArgumentParser(description="Flask API exposing YOLOv5 model")
46
+ parser.add_argument("--port", default=7860, type=int, help="port number")
47
+ args = parser.parse_args()
48
+
49
+ model = torch.hub.load('ultralytics/yolov5', 'custom', path='best2.pt', force_reload=True) # force_reload to recache
50
+ app.run(host="0.0.0.0", port=args.port,debug =True) # debug=True causes Restarting with stat