srivatsavdamaraju commited on
Commit
80f59eb
1 Parent(s): 2bc9379

Update app2.py

Browse files
Files changed (1) hide show
  1. app2.py +6 -6
app2.py CHANGED
@@ -1,8 +1,8 @@
1
- import asyncio
2
  from flask import Flask, request, render_template, Response
3
  import cv2
4
  import numpy as np
5
  import tensorflow as tf
 
6
 
7
  # Load the TFLite model
8
  interpreter = tf.lite.Interpreter(model_path=r'midas.tflite')
@@ -90,18 +90,18 @@ def index():
90
  return render_template('depthmap.html')
91
 
92
  @app.route('/video_feed', methods=['POST'])
93
- async def video_feed():
94
  # Receive the frame from the client
95
- frame_data = await request.files['frame'].read()
96
  nparr = np.frombuffer(frame_data, np.uint8)
97
  frame = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
98
 
99
- # Process the frame asynchronously
100
- processed_frame = await asyncio.to_thread(process_frame, frame)
101
 
102
  # Encode the processed frame as JPEG
103
  _, jpeg = cv2.imencode('.jpg', processed_frame)
104
  return Response(jpeg.tobytes(), mimetype='image/jpeg')
105
 
106
  if __name__ == '__main__':
107
- app.run(debug=True, use_reloader=False)
 
 
1
  from flask import Flask, request, render_template, Response
2
  import cv2
3
  import numpy as np
4
  import tensorflow as tf
5
+ import threading
6
 
7
  # Load the TFLite model
8
  interpreter = tf.lite.Interpreter(model_path=r'midas.tflite')
 
90
  return render_template('depthmap.html')
91
 
92
  @app.route('/video_feed', methods=['POST'])
93
+ def video_feed():
94
  # Receive the frame from the client
95
+ frame_data = request.files['frame'].read()
96
  nparr = np.frombuffer(frame_data, np.uint8)
97
  frame = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
98
 
99
+ # Process the frame
100
+ processed_frame = process_frame(frame)
101
 
102
  # Encode the processed frame as JPEG
103
  _, jpeg = cv2.imencode('.jpg', processed_frame)
104
  return Response(jpeg.tobytes(), mimetype='image/jpeg')
105
 
106
  if __name__ == '__main__':
107
+ app.run(debug=True, threaded=True)