Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,24 +3,33 @@ import time
|
|
3 |
import numpy as np
|
4 |
import mediapipe as mp
|
5 |
|
6 |
-
|
7 |
-
|
8 |
|
9 |
import cv2
|
10 |
from flask import Flask, render_template, request, Response, session, redirect, url_for
|
|
|
11 |
|
12 |
from flask_socketio import SocketIO
|
|
|
|
|
13 |
|
|
|
14 |
import yt_dlp as youtube_dl
|
15 |
-
|
16 |
|
17 |
model_object_detection = YOLO("bisindov2.pt")
|
18 |
|
|
|
|
|
|
|
19 |
app = Flask(__name__)
|
20 |
|
21 |
-
app
|
22 |
-
|
23 |
-
|
|
|
|
|
24 |
|
25 |
|
26 |
######################################################
|
@@ -129,7 +138,6 @@ class VideoStreaming(object):
|
|
129 |
self._model = False
|
130 |
self._mediaPipe = False
|
131 |
self._confidence = 75.0
|
132 |
-
#self.engine = pyttsx3.init()
|
133 |
self.mp_hands = mp.solutions.hands
|
134 |
self.hands = self.mp_hands.Hands()
|
135 |
|
@@ -188,9 +196,6 @@ class VideoStreaming(object):
|
|
188 |
"forceurl": True,
|
189 |
}
|
190 |
|
191 |
-
print("ayoub show")
|
192 |
-
print(url)
|
193 |
-
cap = cv2.VideoCapture(0)
|
194 |
if url == '0':
|
195 |
cap = cv2.VideoCapture(0)
|
196 |
else:
|
@@ -230,10 +235,6 @@ class VideoStreaming(object):
|
|
230 |
list_labels.append(translated_label)
|
231 |
list_labels.append(confidence)
|
232 |
socketio.emit('label', list_labels)
|
233 |
-
|
234 |
-
# Convert the text to speech
|
235 |
-
#self.engine.say(f'الكائن المكتشف: {translated_label} بثقة {confidence}')
|
236 |
-
#self.engine.runAndWait()
|
237 |
|
238 |
if self.mediaPipe:
|
239 |
# Convert the image to RGB for processing with MediaPipe
|
@@ -298,8 +299,8 @@ def video_feed():
|
|
298 |
url = session.get('url', None)
|
299 |
print("video feed: ", url)
|
300 |
if url is None:
|
301 |
-
return
|
302 |
-
|
303 |
return Response(VIDEO.show(url), mimetype='multipart/x-mixed-replace; boundary=frame')
|
304 |
|
305 |
# * Button requests
|
@@ -343,7 +344,8 @@ def stop_process():
|
|
343 |
@socketio.on('connect')
|
344 |
def test_connect():
|
345 |
print('Connected')
|
|
|
346 |
|
347 |
|
348 |
if __name__ == '__main__':
|
349 |
-
socketio.run(app, host="0.0.0.0", allow_unsafe_werkzeug=True,port=7860)
|
|
|
3 |
import numpy as np
|
4 |
import mediapipe as mp
|
5 |
|
6 |
+
import uvicorn
|
7 |
+
from socketio import ASGIApp
|
8 |
|
9 |
import cv2
|
10 |
from flask import Flask, render_template, request, Response, session, redirect, url_for
|
11 |
+
from flask import Flask, render_template
|
12 |
|
13 |
from flask_socketio import SocketIO
|
14 |
+
from flask_socketio import emit
|
15 |
+
from flask_cors import CORS
|
16 |
|
17 |
+
from flask_socketio import SocketIO
|
18 |
import yt_dlp as youtube_dl
|
19 |
+
import uvicorn
|
20 |
|
21 |
model_object_detection = YOLO("bisindov2.pt")
|
22 |
|
23 |
+
|
24 |
+
|
25 |
+
|
26 |
app = Flask(__name__)
|
27 |
|
28 |
+
socketio = SocketIO(app, cors_allowed_origins="*")
|
29 |
+
|
30 |
+
CORS(app)
|
31 |
+
|
32 |
+
app.secret_key = 'flask-sockets-builds'
|
33 |
|
34 |
|
35 |
######################################################
|
|
|
138 |
self._model = False
|
139 |
self._mediaPipe = False
|
140 |
self._confidence = 75.0
|
|
|
141 |
self.mp_hands = mp.solutions.hands
|
142 |
self.hands = self.mp_hands.Hands()
|
143 |
|
|
|
196 |
"forceurl": True,
|
197 |
}
|
198 |
|
|
|
|
|
|
|
199 |
if url == '0':
|
200 |
cap = cv2.VideoCapture(0)
|
201 |
else:
|
|
|
235 |
list_labels.append(translated_label)
|
236 |
list_labels.append(confidence)
|
237 |
socketio.emit('label', list_labels)
|
|
|
|
|
|
|
|
|
238 |
|
239 |
if self.mediaPipe:
|
240 |
# Convert the image to RGB for processing with MediaPipe
|
|
|
299 |
url = session.get('url', None)
|
300 |
print("video feed: ", url)
|
301 |
if url is None:
|
302 |
+
return redirect(url_for('homepage'))
|
303 |
+
print("video feed: ", url)
|
304 |
return Response(VIDEO.show(url), mimetype='multipart/x-mixed-replace; boundary=frame')
|
305 |
|
306 |
# * Button requests
|
|
|
344 |
@socketio.on('connect')
|
345 |
def test_connect():
|
346 |
print('Connected')
|
347 |
+
#emit('message', data, broadcast=True)
|
348 |
|
349 |
|
350 |
if __name__ == '__main__':
|
351 |
+
socketio.run(app, host="0.0.0.0", allow_unsafe_werkzeug=True,port=7860)
|