Spaces:
Sleeping
Sleeping
Jon Taylor
commited on
Commit
·
690cc6d
1
Parent(s):
6e1bb73
fixed memory buffer
Browse files- app/bot.py +7 -5
- app/pipeline.py +2 -0
- frontend/app/page.js +15 -13
app/bot.py
CHANGED
|
@@ -32,6 +32,7 @@ class DailyVision(EventHandler):
|
|
| 32 |
self.__time = time.time()
|
| 33 |
self.__queue = queue.Queue()
|
| 34 |
self.__app_quit = False
|
|
|
|
| 35 |
self.__bot_name = bot_name
|
| 36 |
self.__room_url = room_url
|
| 37 |
self.__room_name = room_name
|
|
@@ -79,7 +80,7 @@ class DailyVision(EventHandler):
|
|
| 79 |
|
| 80 |
def on_participant_joined(self, participant):
|
| 81 |
self.logger.info(f"Participant {participant['id']} joined, analyzing frames...")
|
| 82 |
-
self.__client.set_video_renderer(participant["id"], self.on_video_frame)
|
| 83 |
|
| 84 |
# Say hello
|
| 85 |
self.wave()
|
|
@@ -114,13 +115,13 @@ class DailyVision(EventHandler):
|
|
| 114 |
self.__app_quit = True
|
| 115 |
break
|
| 116 |
try:
|
| 117 |
-
video_frame = self.__queue.get(timeout=5)
|
|
|
|
| 118 |
|
| 119 |
-
if video_frame:
|
| 120 |
image = Image.frombytes("RGB", (video_frame.width, video_frame.height), video_frame.buffer)
|
| 121 |
result_image = self.__pipeline.predict(params, image)
|
| 122 |
self.__camera.write_frame(result_image.tobytes())
|
| 123 |
-
#pil = Image.fromarray(result.render()[0], mode="RGB").tobytes()
|
| 124 |
except queue.Empty:
|
| 125 |
pass
|
| 126 |
|
|
@@ -128,7 +129,8 @@ class DailyVision(EventHandler):
|
|
| 128 |
# Process ~15 frames per second (considering incoming frames at 30fps).
|
| 129 |
if time.time() - self.__time > 2: #0.05:
|
| 130 |
self.__time = time.time()
|
| 131 |
-
self.
|
|
|
|
| 132 |
|
| 133 |
def wave(self, emoji="👋"):
|
| 134 |
self.__client.send_app_message(
|
|
|
|
| 32 |
self.__time = time.time()
|
| 33 |
self.__queue = queue.Queue()
|
| 34 |
self.__app_quit = False
|
| 35 |
+
self.__image_buffer = None
|
| 36 |
self.__bot_name = bot_name
|
| 37 |
self.__room_url = room_url
|
| 38 |
self.__room_name = room_name
|
|
|
|
| 80 |
|
| 81 |
def on_participant_joined(self, participant):
|
| 82 |
self.logger.info(f"Participant {participant['id']} joined, analyzing frames...")
|
| 83 |
+
self.__client.set_video_renderer(participant["id"], self.on_video_frame, color_format="RGB")
|
| 84 |
|
| 85 |
# Say hello
|
| 86 |
self.wave()
|
|
|
|
| 115 |
self.__app_quit = True
|
| 116 |
break
|
| 117 |
try:
|
| 118 |
+
#video_frame = self.__queue.get(timeout=5)
|
| 119 |
+
video_frame = self.__image_buffer
|
| 120 |
|
| 121 |
+
if not video_frame == None:
|
| 122 |
image = Image.frombytes("RGB", (video_frame.width, video_frame.height), video_frame.buffer)
|
| 123 |
result_image = self.__pipeline.predict(params, image)
|
| 124 |
self.__camera.write_frame(result_image.tobytes())
|
|
|
|
| 125 |
except queue.Empty:
|
| 126 |
pass
|
| 127 |
|
|
|
|
| 129 |
# Process ~15 frames per second (considering incoming frames at 30fps).
|
| 130 |
if time.time() - self.__time > 2: #0.05:
|
| 131 |
self.__time = time.time()
|
| 132 |
+
self.__image_buffer = video_frame
|
| 133 |
+
#self.__queue.put(video_frame)
|
| 134 |
|
| 135 |
def wave(self, emoji="👋"):
|
| 136 |
self.__client.send_app_message(
|
app/pipeline.py
CHANGED
|
@@ -222,11 +222,13 @@ class Pipeline:
|
|
| 222 |
return None
|
| 223 |
result_image = results.images[0]
|
| 224 |
|
|
|
|
| 225 |
if os.getenv("CONTROL_NET_OVERLAY", True):
|
| 226 |
# paste control_image on top of result_image
|
| 227 |
w0, h0 = (200, 200)
|
| 228 |
control_image = control_image.resize((w0, h0))
|
| 229 |
w1, h1 = result_image.size
|
| 230 |
result_image.paste(control_image, (w1 - w0, h1 - h0))
|
|
|
|
| 231 |
|
| 232 |
return result_image
|
|
|
|
| 222 |
return None
|
| 223 |
result_image = results.images[0]
|
| 224 |
|
| 225 |
+
"""
|
| 226 |
if os.getenv("CONTROL_NET_OVERLAY", True):
|
| 227 |
# paste control_image on top of result_image
|
| 228 |
w0, h0 = (200, 200)
|
| 229 |
control_image = control_image.resize((w0, h0))
|
| 230 |
w1, h1 = result_image.size
|
| 231 |
result_image.paste(control_image, (w1 - w0, h1 - h0))
|
| 232 |
+
"""
|
| 233 |
|
| 234 |
return result_image
|
frontend/app/page.js
CHANGED
|
@@ -9,19 +9,21 @@ export default function Home() {
|
|
| 9 |
|
| 10 |
async function start() {
|
| 11 |
setStarting(true);
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
| 25 |
|
| 26 |
const data = await resp.json();
|
| 27 |
|
|
|
|
| 9 |
|
| 10 |
async function start() {
|
| 11 |
setStarting(true);
|
| 12 |
+
|
| 13 |
+
const apiUrl = `${
|
| 14 |
+
window.location.protocol === "https:" ? "https" : "http"
|
| 15 |
+
}:${window.location.host}`;
|
| 16 |
+
|
| 17 |
+
const resp = await fetch(`${process.env.API_URL || apiUrl}/start`, {
|
| 18 |
+
method: "POST",
|
| 19 |
+
mode: "cors",
|
| 20 |
+
cache: "no-cache",
|
| 21 |
+
credentials: "same-origin",
|
| 22 |
+
headers: {
|
| 23 |
+
"Content-Type": "application/json",
|
| 24 |
+
},
|
| 25 |
+
body: JSON.stringify({}),
|
| 26 |
+
});
|
| 27 |
|
| 28 |
const data = await resp.json();
|
| 29 |
|