jbilcke-hf HF staff commited on
Commit
ea331ab
Β·
1 Parent(s): ad68cdf
Files changed (4) hide show
  1. app.py +0 -12
  2. client/src/lib/facePoke.ts +9 -39
  3. engine.py +2 -22
  4. public/index.js +0 -19
app.py CHANGED
@@ -139,16 +139,6 @@ async def hf_logo(request: web.Request) -> web.Response:
139
  content = open(os.path.join(os.path.dirname(__file__), "public", "hf-logo.svg"), "r").read()
140
  return web.Response(content_type="image/svg+xml", text=content)
141
 
142
- async def on_shutdown(app: web.Application):
143
- """Cleanup function to be called on server shutdown."""
144
- logger.info("Server shutdown initiated, cleaning up resources...")
145
-
146
- if 'engine' in app:
147
- await app['engine'].cleanup()
148
- logger.info("Engine instance cleaned up")
149
-
150
- logger.info("Server shutdown complete")
151
-
152
  async def initialize_app() -> web.Application:
153
  """Initialize and configure the web application."""
154
  try:
@@ -161,8 +151,6 @@ async def initialize_app() -> web.Application:
161
  app = web.Application()
162
  app['engine'] = engine
163
 
164
- app.on_shutdown.append(on_shutdown)
165
-
166
  # Configure routes
167
  app.router.add_get("/", index)
168
  app.router.add_get("/index.js", js_index)
 
139
  content = open(os.path.join(os.path.dirname(__file__), "public", "hf-logo.svg"), "r").read()
140
  return web.Response(content_type="image/svg+xml", text=content)
141
 
 
 
 
 
 
 
 
 
 
 
142
  async def initialize_app() -> web.Application:
143
  """Initialize and configure the web application."""
144
  try:
 
151
  app = web.Application()
152
  app['engine'] = engine
153
 
 
 
154
  # Configure routes
155
  app.router.add_get("/", index)
156
  app.router.add_get("/index.js", js_index)
client/src/lib/facePoke.ts CHANGED
@@ -248,49 +248,19 @@ export class FacePoke {
248
  }
249
 
250
  /**
251
- * Handles interruption messages from the server.
252
- * @param message - The interruption message.
253
  */
254
- private handleInterruption(message: string): void {
255
- console.warn(`[FacePoke] Interruption: ${message}`);
256
- this.emitEvent('interruption', message);
257
- }
258
-
259
- /**
260
- * Toggles the microphone on or off.
261
- * @param isOn - Whether to turn the microphone on (true) or off (false).
262
- */
263
- public async toggleMicrophone(isOn: boolean): Promise<void> {
264
- console.log(`[FacePoke] Attempting to ${isOn ? 'start' : 'stop'} microphone`);
265
- try {
266
- if (isOn) {
267
- await this.startMicrophone();
268
- } else {
269
- this.stopMicrophone();
270
- }
271
- this.emitEvent('microphoneToggled', isOn);
272
- } catch (error) {
273
- console.error(`[FacePoke] Error toggling microphone:`, error);
274
- this.emitEvent('microphoneError', error);
275
- throw error;
276
  }
 
 
 
277
  }
278
 
279
-
280
- /**
281
- * Cleans up resources and closes connections.
282
- */
283
- public cleanup(): void {
284
- console.log('[FacePoke] Starting cleanup process');
285
- if (this.ws) {
286
- this.ws.close();
287
- this.ws = null;
288
- }
289
- this.eventListeners.clear();
290
- console.log('[FacePoke] Cleanup completed');
291
- this.emitEvent('cleanup');
292
- }
293
-
294
  /**
295
  * Modifies an image based on the provided parameters
296
  * @param image - The data-uri base64 image to modify.
 
248
  }
249
 
250
  /**
251
+ * Cleans up resources and closes connections.
 
252
  */
253
+ public cleanup(): void {
254
+ console.log('[FacePoke] Starting cleanup process');
255
+ if (this.ws) {
256
+ this.ws.close();
257
+ this.ws = null;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
258
  }
259
+ this.eventListeners.clear();
260
+ console.log('[FacePoke] Cleanup completed');
261
+ this.emitEvent('cleanup');
262
  }
263
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264
  /**
265
  * Modifies an image based on the provided parameters
266
  * @param image - The data-uri base64 image to modify.
engine.py CHANGED
@@ -1,26 +1,20 @@
1
- import time
2
  import logging
3
  import hashlib
4
- import uuid
5
  import os
6
  import io
7
- import shutil
8
  import asyncio
9
  import base64
10
- from concurrent.futures import ThreadPoolExecutor
11
  from queue import Queue
12
- from typing import Dict, Any, List, Optional, AsyncGenerator, Tuple, Union
13
  from functools import lru_cache
14
- import av
15
  import numpy as np
16
- import cv2
17
  import torch
18
  import torch.nn.functional as F
19
  from PIL import Image
20
 
21
  from liveportrait.config.argument_config import ArgumentConfig
22
  from liveportrait.utils.camera import get_rotation_matrix
23
- from liveportrait.utils.io import load_image_rgb, load_driving_info, resize_to_limit
24
  from liveportrait.utils.crop import prepare_paste_back, paste_back
25
 
26
  # Configure logging
@@ -62,7 +56,6 @@ class Engine:
62
 
63
  self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
64
 
65
- # cache for the "modify image" workflow
66
  self.image_cache = {} # Stores the original images
67
  self.processed_cache = {} # Stores the processed image data
68
 
@@ -273,19 +266,6 @@ class Engine:
273
  x_d_new[0, 15, 1] -= params.get('pupil_y', 0) * 0.001
274
  params['eyes'] = params.get('eyes', 0) - params.get('pupil_y', 0) / 2.
275
 
276
- async def cleanup(self):
277
- """
278
- Perform cleanup operations for the Engine.
279
- This method should be called when shutting down the application.
280
- """
281
- logger.info("Starting Engine cleanup")
282
- try:
283
- # TODO: Add any additional cleanup operations here
284
- logger.info("Engine cleanup completed successfully")
285
- except Exception as e:
286
- logger.error(f"Error during Engine cleanup: {str(e)}")
287
- logger.exception("Full traceback:")
288
-
289
  def create_engine(models):
290
  logger.info("Creating Engine instance...")
291
 
 
 
1
  import logging
2
  import hashlib
 
3
  import os
4
  import io
 
5
  import asyncio
6
  import base64
 
7
  from queue import Queue
8
+ from typing import Dict, Any, List, Optional, Union
9
  from functools import lru_cache
 
10
  import numpy as np
 
11
  import torch
12
  import torch.nn.functional as F
13
  from PIL import Image
14
 
15
  from liveportrait.config.argument_config import ArgumentConfig
16
  from liveportrait.utils.camera import get_rotation_matrix
17
+ from liveportrait.utils.io import resize_to_limit
18
  from liveportrait.utils.crop import prepare_paste_back, paste_back
19
 
20
  # Configure logging
 
56
 
57
  self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
58
 
 
59
  self.image_cache = {} # Stores the original images
60
  self.processed_cache = {} # Stores the processed image data
61
 
 
266
  x_d_new[0, 15, 1] -= params.get('pupil_y', 0) * 0.001
267
  params['eyes'] = params.get('eyes', 0) - params.get('pupil_y', 0) / 2.
268
 
 
 
 
 
 
 
 
 
 
 
 
 
 
269
  def create_engine(models):
270
  logger.info("Creating Engine instance...")
271
 
public/index.js CHANGED
@@ -29858,25 +29858,6 @@ class FacePoke {
29858
  console.error(`[FacePoke][${this.connectionId}] WebSocket error:`, error);
29859
  this.emitEvent("websocketError", error);
29860
  }
29861
- handleInterruption(message) {
29862
- console.warn(`[FacePoke] Interruption: ${message}`);
29863
- this.emitEvent("interruption", message);
29864
- }
29865
- async toggleMicrophone(isOn) {
29866
- console.log(`[FacePoke] Attempting to ${isOn ? "start" : "stop"} microphone`);
29867
- try {
29868
- if (isOn) {
29869
- await this.startMicrophone();
29870
- } else {
29871
- this.stopMicrophone();
29872
- }
29873
- this.emitEvent("microphoneToggled", isOn);
29874
- } catch (error) {
29875
- console.error(`[FacePoke] Error toggling microphone:`, error);
29876
- this.emitEvent("microphoneError", error);
29877
- throw error;
29878
- }
29879
- }
29880
  cleanup() {
29881
  console.log("[FacePoke] Starting cleanup process");
29882
  if (this.ws) {
 
29858
  console.error(`[FacePoke][${this.connectionId}] WebSocket error:`, error);
29859
  this.emitEvent("websocketError", error);
29860
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29861
  cleanup() {
29862
  console.log("[FacePoke] Starting cleanup process");
29863
  if (this.ws) {