Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) Add FreeSimpleGUI, package manager unification, bugfixes #94

Merged
merged 8 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion BabbleApp/algo_settings_widget.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import PySimpleGUI as sg
import FreeSimpleGUI as sg
from config import BabbleSettingsConfig
from osc import Tab
from queue import Queue
Expand Down
2 changes: 1 addition & 1 deletion BabbleApp/babble_model_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
os.environ["OMP_NUM_THREADS"] = "1"
import onnxruntime as ort
import time
import PySimpleGUI as sg
import FreeSimpleGUI as sg
import cv2
import numpy as np
from pythonosc import udp_client
Expand Down
11 changes: 5 additions & 6 deletions BabbleApp/babble_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import cv2
from enum import Enum
from one_euro_filter import OneEuroFilter
from utils.misc_utils import PlaySound, SND_FILENAME, SND_ASYNC
from utils.misc_utils import playSound, onnx_providers
import importlib
from osc import Tab
from osc_calibrate_filter import *
Expand All @@ -37,7 +37,7 @@ def wrapper(*args, **kwargs):
async def delayed_setting_change(setting, value):
await asyncio.sleep(5)
setting = value
PlaySound("Audio/completed.wav", SND_FILENAME | SND_ASYNC)
playSound(os.path.join("Audio", "completed.wav"))


class BabbleProcessor:
Expand Down Expand Up @@ -102,15 +102,14 @@ def __init__(
self.opts.enable_mem_pattern = False
if self.runtime in ("ONNX", "Default (ONNX)"): # ONNX
if self.use_gpu:
provider = "DmlExecutionProvider"
provider = onnx_providers
else:
provider = "CPUExecutionProvider" # Build onnxruntime to get both DML and OpenVINO
provider = [onnx_providers[-1]]
try:
self.sess = ort.InferenceSession(
f"{self.model}/onnx/model.onnx",
self.opts,
providers=[provider],
provider_options=[{"device_id": self.gpu_index}],
providers=provider,
)
except: # Load default model if we can't find the specified model
print(
Expand Down
8 changes: 4 additions & 4 deletions BabbleApp/babbleapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"""

import os
import PySimpleGUI as sg
import FreeSimpleGUI as sg
import queue
import requests
import threading
Expand All @@ -33,13 +33,13 @@
from algo_settings_widget import AlgoSettingsWidget
from calib_settings_widget import CalibSettingsWidget
from notification_manager import NotificationManager
from utils.misc_utils import EnsurePath, is_nt, bg_color_highlight, bg_color_clear
from utils.misc_utils import ensurePath, os_type, bg_color_highlight, bg_color_clear
from lang_manager import LocaleStringManager as lang
from logger import setup_logging

winmm = None

if is_nt:
if os_type == 'Windows':
try:
from ctypes import windll
winmm = windll.winmm
Expand Down Expand Up @@ -99,7 +99,7 @@ async def check_for_updates(config, notification_manager):
)

async def async_main():
EnsurePath()
ensurePath()
setup_logging()

# Get Configuration
Expand Down
2 changes: 1 addition & 1 deletion BabbleApp/calib_settings_widget.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import PySimpleGUI as sg
import FreeSimpleGUI as sg

from config import BabbleSettingsConfig
from osc import Tab
Expand Down
4 changes: 2 additions & 2 deletions BabbleApp/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from lang_manager import LocaleStringManager as lang
from colorama import Fore
from config import BabbleConfig, BabbleSettingsConfig
from utils.misc_utils import get_camera_index_by_name, list_camera_names, is_nt
from utils.misc_utils import get_camera_index_by_name, list_camera_names, os_type

from vivefacialtracker.vivetracker import ViveTracker
from vivefacialtracker.camera_controller import FTCameraController
Expand Down Expand Up @@ -321,7 +321,7 @@ def start_serial_connection(self, port):
rate = 115200 if sys.platform == "darwin" else 3000000 # Higher baud rate not working on macOS
conn = serial.Serial(baudrate=rate, port=port, xonxoff=False, dsrdtr=False, rtscts=False)
# Set explicit buffer size for serial. This function is Windows only!
if is_nt:
if os_type == 'Windows':
conn.set_buffer_size(rx_size=BUFFER_SIZE, tx_size=BUFFER_SIZE)

print(
Expand Down
10 changes: 4 additions & 6 deletions BabbleApp/camera_widget.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
from collections import deque
from queue import Queue, Empty
from threading import Event, Thread
import PySimpleGUI as sg
import FreeSimpleGUI as sg
import cv2
import os
from babble_processor import BabbleProcessor, CamInfoOrigin
from camera import Camera, CameraState, MAX_RESOLUTION
from config import BabbleConfig
from osc import Tab
from utils.misc_utils import (
PlaySound,
SND_FILENAME,
SND_ASYNC,
playSound,
list_camera_names,
get_camera_index_by_name,
bg_color_highlight,
Expand All @@ -19,7 +18,6 @@
)
from lang_manager import LocaleStringManager as lang


class CameraWidget:
def __init__(self, widget_id: Tab, main_config: BabbleConfig, osc_queue: Queue):
self.gui_camera_addr = f"-CAMERAADDR{widget_id}-"
Expand Down Expand Up @@ -441,7 +439,7 @@ def render(self, window, event, values):
values[self.use_calibration] == True
): # Don't start recording if the calibration filter is disabled.
self.babble_cnn.calibration_frame_counter = 1500
PlaySound("Audio/start.wav", SND_FILENAME | SND_ASYNC)
playSound(os.path.join("Audio", "start.wav"))

if event == self.gui_stop_calibration:
if (
Expand Down
6 changes: 3 additions & 3 deletions BabbleApp/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os.path
import shutil

from utils.misc_utils import EnsurePath
from utils.misc_utils import ensurePath
from tab import Tab
from pydantic import BaseModel
from typing import Union
Expand Down Expand Up @@ -64,7 +64,7 @@ class BabbleConfig(BaseModel):

@staticmethod
def load():
EnsurePath()
ensurePath()

if not os.path.exists(CONFIG_FILE_NAME):
return BabbleConfig()
Expand All @@ -84,7 +84,7 @@ def load():
return load_config

def save(self):
EnsurePath()
ensurePath()

# make sure this is only called if there is a change
if os.path.exists(CONFIG_FILE_NAME):
Expand Down
2 changes: 1 addition & 1 deletion BabbleApp/general_settings_widget.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import PySimpleGUI as sg
import FreeSimpleGUI as sg
from lang_manager import LocaleStringManager as lang
from config import BabbleSettingsConfig
from osc import Tab
Expand Down
2 changes: 1 addition & 1 deletion BabbleApp/landmark_model_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
os.environ["OMP_NUM_THREADS"] = "1"
import onnxruntime as ort
import time
import PySimpleGUI as sg
import FreeSimpleGUI as sg
import cv2
import numpy as np
from pythonosc import udp_client
Expand Down
20 changes: 10 additions & 10 deletions BabbleApp/landmark_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
import cv2
from enum import Enum
from one_euro_filter import OneEuroFilter
from utils.misc_utils import PlaySound, SND_FILENAME, SND_ASYNC
#import importlib
#from osc import Tab
from utils.misc_utils import playSound, onnx_providers
from osc_calibrate_filter import *
from tab import CamInfo, CamInfoOrigin
from landmark_model_loader import *
Expand All @@ -30,13 +28,10 @@ def wrapper(*args, **kwargs):
wrapper.has_run = False
return wrapper


async def delayed_setting_change(setting, value):
await asyncio.sleep(5)
setting = value
PlaySound('Audio/completed.wav', SND_FILENAME | SND_ASYNC)


playSound(os.path.join("Audio", "completed.wav"))

class LandmarkProcessor:
def __init__(
Expand Down Expand Up @@ -96,9 +91,14 @@ def __init__(
self.opts.add_session_config_entry("session.intra_op.allow_spinning", "0") # ~3% savings worth ~6ms avg latency. Not noticeable at 60fps?
self.opts.enable_mem_pattern = False
if self.runtime in ("ONNX", "Default (ONNX)"): # ONNX
if self.use_gpu: provider = 'DmlExecutionProvider'
else: provider = "CPUExecutionProvider" # Build onnxruntime to get both DML and OpenVINO
self.sess = ort.InferenceSession(f'{self.model}onnx/model.onnx', self.opts, providers=[provider, ], provider_options=[{'device_id': self.gpu_index}]) # Load Babble CNN until PFLD has been converted
if self.use_gpu:
provider = onnx_providers
else:
provider = [onnx_providers[-1]]
self.sess = ort.InferenceSession(
f'{self.model}onnx/model.onnx',
self.opts,
providers=onnx_providers)
self.input_name = self.sess.get_inputs()[0].name
self.output_name = self.sess.get_outputs()[0].name
try:
Expand Down
4 changes: 2 additions & 2 deletions BabbleApp/notification_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pathlib import Path
from desktop_notifier import DesktopNotifier, Urgency, Button, Icon, DEFAULT_SOUND
from lang_manager import LocaleStringManager as lang
from utils.misc_utils import is_nt
from utils.misc_utils import os_type

class NotificationManager:
def __init__(self):
Expand Down Expand Up @@ -46,6 +46,6 @@ async def initialize(self):
self.loop = asyncio.get_running_loop()

# Add non nt signal handlers
if not is_nt:
if not os_type == 'Windows':
self.loop.add_signal_handler(signal.SIGINT, self.stop_event.set)
self.loop.add_signal_handler(signal.SIGTERM, self.stop_event.set)
8 changes: 3 additions & 5 deletions BabbleApp/osc.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
from pythonosc import udp_client, osc_server, dispatcher
from utils.misc_utils import PlaySound, SND_FILENAME, SND_ASYNC
from utils.misc_utils import playSound
import queue
import threading
from enum import IntEnum
import time
from config import BabbleConfig
import traceback
import math
import os
from lang_manager import LocaleStringManager as lang


class Tab(IntEnum):
CAM = 0
SETTINGS = 1
ALGOSETTINGS = 2
CALIBRATION = 3


import numpy as np


def delay_output_osc(array, delay_seconds, self):
time.sleep(delay_seconds)
output_osc(array, self)
Expand Down Expand Up @@ -152,7 +150,7 @@ def recalibrate_mouth(self, address, osc_value):
if osc_value:
for cam in self.cams:
cam.babble_cnn.calibration_frame_counter = 300
PlaySound("Audio/start.wav", SND_FILENAME | SND_ASYNC)
playSound(os.path.join("Audio", "start.wav"))

def run(self):

Expand Down
8 changes: 3 additions & 5 deletions BabbleApp/osc_calibrate_filter.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import numpy as np
from math import log
from enum import IntEnum
from utils.misc_utils import PlaySound, SND_FILENAME, SND_ASYNC
from utils.misc_utils import playSound
import os
from lang_manager import LocaleStringManager as lang


class CamId(IntEnum):
CAM = 0
SETTINGS = 1


class cal:

def __init__(self):
self.calibration_frame_counter = None
self.calibrated_array = None
Expand Down Expand Up @@ -57,7 +55,7 @@ def cal_osc(self, array):
f'[{lang._instance.get_string("log.info")}] Calibration completed.'
)

PlaySound("Audio/completed.wav", SND_FILENAME | SND_ASYNC)
playSound(os.path.join("Audio", "completed.wav"))

if self.settings.calibration_mode == "Neutral":
self.min_max_array = np.fromstring(
Expand Down
36 changes: 20 additions & 16 deletions BabbleApp/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
onnxruntime==1.19.2
opencv_python==4.10.0.84
pillow==11.0.0
pysimplegui==4.70.1
python_osc==1.9.0
torch==2.4.1
torchvision==0.19.1
pydantic==1.10.18
pyserial==3.5
colorama==0.4.6
desktop-notifier==6.0.0
comtypes==1.4.8
pygrabber==0.2
poetry
v4l2py
psutil
onnxruntime==1.19.2;
onnxruntime-directml==1.19.2; platform_system == "Windows"
onnxruntime-gpu==1.19.2; platform_system == "Linux"
torch==2.6.0;
torchvision==0.21.0;
opencv_python==4.11.0.86;
pillow==11.0.0;
FreeSimpleGUI==5.1.1;
python_osc==1.9.0;
pydantic==2.10.6;
pyserial==3.5;
colorama==0.4.6;
desktop-notifier==6.0.0;
comtypes==1.4.8;
pygrabber==0.2;
psutil==7.0.0;
requests==2.32.3;
v4l2py==3.0.0;
sounddevice=0.5.1;
soundfile-0.13.1;
Loading