<jupyter_start><jupyter_text>Test Face Diarization with OpenFace<jupyter_code>from moviepy.editor import VideoFileClip
import subprocess
import os
import IPython
import docker
import pandas as pd

client = docker.from_env()

SAVE_DIR = "video_debate_21"
VIDEO_FILE = "debate_2021_compressed.mp4"

def extract_features_video_docker(client, filename, logfilename):
    """ 
    Extracts openface features from a single face in a video file using a docker container. 
    Copies video file into the openface docker container.
    Extracts openface features in docker container.
    Saves openface log to a logfile.
    Copies results (processed files) back to working directory. 
    """
    container = client.containers.run(
        "algebr/openface:latest", name="openface", stdin_open=True, tty=True, remove=True, detach=True)
    print("Started docker container")

    with open(logfilename, "wb") as logfile:
        subprocess.run(
            f"docker cp {filename} openface:/home/openface-build", shell=True)
        print("Copied file to docker container")
        _, output = container.exec_run(
            f"build/bin/FeatureExtraction -f {filename.split('/')[-1]}")
        print("Extracted openface features")
        subprocess.run(
            "docker cp openface:/home/openface-build/processed .", shell=True)
        print("Copied results from docker container to /processed")
        logfile.write(output)

    container.stop()
    print("Stopped docker container")

if not os.path.isfile(f"{SAVE_DIR}/debate_21_short.mp4"):
    with VideoFileClip(f"{SAVE_DIR}/{VIDEO_FILE}") as clip:
        short_clip = clip.subclip(30*60, 35*60)
        short_clip.write_videofile(f"{SAVE_DIR}/debate_21_short.mp4")

extract_features_video_docker(
    client, f"{SAVE_DIR}/debate_21_short.mp4", f"{SAVE_DIR}/debate_21_short.log")

features = pd.read_csv("processed/debate_21_short.csv")

features

set(features.iloc[:, 1])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10685071574642127, 'fraction_numerical': 0.015337423312883436, 'mean_word_length': 4.030848329048843, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '516785', 'license': 'Apache-2.0', 'n_tokens_mistral': 670, 'n_tokens_neox': 626, 'n_words': 145, 'path': 'test_openface.ipynb', 'repo_name': 'mexca/mexca-exploration', 'size': '1956'}