Add local AI media tools for Fedora desktop

This commit is contained in:
Fabio Scotto di Santolo
2026-10-25 16:42:58 +01:00
parent 479b60f270
commit 7b6d5396ab
16 changed files with 1182 additions and 1 deletions

View File

@@ -0,0 +1,40 @@
FROM {{ desktop_ai_media_base_image }}
LABEL io.fscotto.ai-media.models="{{ desktop_ai_media_public_models | selectattr('app', 'equalto', item) | list | to_json | hash('sha256') }}"
ENV DEBIAN_FRONTEND=noninteractive PIP_DISABLE_PIP_VERSION_CHECK=1
RUN sed -i \
-e 's|http://deb.debian.org/debian$|https://snapshot.debian.org/archive/debian/{{ desktop_ai_media_debian_snapshot }}/|' \
-e 's|http://deb.debian.org/debian-security$|https://snapshot.debian.org/archive/debian-security/{{ desktop_ai_media_debian_snapshot }}/|' \
/etc/apt/sources.list.d/debian.sources \
&& apt-get -o Acquire::Check-Valid-Until=false update \
&& apt-get install -y --no-install-recommends \
ca-certificates curl git ffmpeg firefox-esr fonts-dejavu-core libgl1 libglib2.0-0 libportaudio2 \
&& rm -rf /var/lib/apt/lists/*
COPY requirements-{{ item }}.lock /opt/requirements.lock
WORKDIR /opt/app
{% if item == 'facefusion' %}
RUN git init . && git remote add origin https://github.com/facefusion/facefusion.git \
&& git fetch --depth 1 origin {{ desktop_ai_media_facefusion_revision }} \
&& git checkout --detach FETCH_HEAD && rm -rf .git \
&& pip install --no-cache-dir -r /opt/requirements.lock
{% else %}
RUN git init . && git remote add origin https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI.git \
&& git fetch --depth 1 origin {{ desktop_ai_media_rvc_revision }} \
&& git checkout --detach FETCH_HEAD && rm -rf .git \
&& pip install --no-cache-dir -r /opt/requirements.lock
{% endif %}
{% for model in desktop_ai_media_public_models if model.app == item %}
COPY models/{{ model.app }}/{{ model.path }} /opt/app/{{ model.path }}
{% endfor %}
COPY prepare.py /opt/
RUN python /opt/prepare.py {{ item }} \
&& pip freeze --all > /opt/python-requirements.lock \
&& test -s /opt/model-checksums.sha256
COPY session.py verify.py /opt/
RUN mkdir -p /work/input /work/output /work/state /work/models /home/media
ENV GRADIO_ANALYTICS_ENABLED=False HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1 \
HF_HUB_DISABLE_TELEMETRY=1 DO_NOT_TRACK=1 HOME=/home/media \
XDG_RUNTIME_DIR=/run/media MOZ_ENABLE_WAYLAND=1 GTK_USE_PORTAL=0 \
LIBGL_ALWAYS_SOFTWARE=1 GRADIO_SERVER_NAME=127.0.0.1 GRADIO_SERVER_PORT=7860 \
PYTHONPATH=/opt/app PYTHONSAFEPATH=1 PYTHONDONTWRITEBYTECODE=1 NUMBA_CACHE_DIR=/tmp/numba MPLCONFIGDIR=/tmp/matplotlib \
GRADIO_TEMP_DIR=/tmp/gradio APP={{ item }}
ENTRYPOINT ["python", "/opt/session.py"]

View File

@@ -0,0 +1,79 @@
#!/usr/bin/env bash
set -euo pipefail
root={{ desktop_ai_media_root | quote }}
app="${1:-}"
case "$app" in
facefusion|rvc) shift ;;
ffmpeg) app=facefusion; shift; set -- ffmpeg "$@" ;;
verify)
for tool in facefusion rvc; do
podman --remote=false run --rm --pull=never --network=none --read-only \
--cap-drop=ALL --cap-add=SYS_CHROOT \
--security-opt=no-new-privileges --userns=keep-id --http-proxy=false \
--tmpfs "/tmp:rw,nosuid,nodev,size=4g,mode=1777" \
--tmpfs "/home/media:rw,nosuid,nodev,size=128m,mode=1777" \
--tmpfs "/work/state:rw,nosuid,nodev,size=128m,mode=1777" \
--tmpfs "/work/models:rw,nosuid,nodev,size=128m,mode=1777" \
"localhost/ai-media-$tool:managed" verify
done
exit 0 ;;
*) echo "Usage: ai-media {facefusion|rvc|ffmpeg|verify} [cli ...]" >&2; exit 2 ;;
esac
# Fail closed if an existing data path was replaced by a symlink.
for path in "$root" "$root/input" "$root/output" "$root/models" "$root/state/$app"; do
[[ -d "$path" && "$(realpath -- "$path")" == "$path" ]] || {
echo "Unsafe or missing media directory: $path" >&2; exit 1;
}
done
python3 {{ (desktop_ai_media_build_root + "/check_storage.py") | quote }} "$root"
# Run interactive sessions under the user manager, not the launching terminal.
# No autostart or automatic restart: recovering a training run remains explicit.
if [[ "$app" == rvc || "$app" == facefusion ]] && [[ $# -eq 0 ]]; then
: "${XDG_RUNTIME_DIR:?Run this launcher from the GNOME Wayland session}"
: "${WAYLAND_DISPLAY:?A Wayland session is required}"
[[ "$WAYLAND_DISPLAY" != */* && -S "$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY" ]] || exit 1
active=$(podman --remote=false ps --filter "ancestor=localhost/ai-media-$app:managed" --format '{{ '{{.ID}}' }}')
if [[ -n "$active" ]]; then
echo "$app is already running; leave its training session open." >&2
exit 1
fi
exec systemd-run --user --collect --unit="ai-media-$app" \
--property=Type=exec --property=Restart=no --property=Delegate=yes \
--setenv="XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR" --setenv="WAYLAND_DISPLAY=$WAYLAND_DISPLAY" \
-- /usr/bin/bash "$(realpath -- "$0")" "$app" --foreground
fi
if [[ "${1:-}" == --foreground ]]; then
shift
fi
args=(
run --rm --pull=never --network=none --read-only --userns=keep-id --http-proxy=false
--cap-drop=ALL --security-opt=no-new-privileges
--tmpfs "/tmp:rw,nosuid,nodev,size=8g,mode=1777"
--tmpfs "/home/media:rw,nosuid,nodev,size=128m,mode=1777"
--shm-size=512m
--volume "$root/input:/work/input:ro,Z"
--volume "$root/output:/work/output:rw,Z"
--volume "$root/models:/work/models:ro,Z"
--volume "$root/state/$app:/work/state:rw,Z"
)
if [[ "${1:-}" != cli && "${1:-}" != ffmpeg ]]; then
: "${XDG_RUNTIME_DIR:?Run this launcher from the GNOME Wayland session}"
: "${WAYLAND_DISPLAY:?A Wayland session is required}"
[[ "$WAYLAND_DISPLAY" != */* && -S "$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY" ]] || exit 1
# Share only the display socket, never the runtime directory, D-Bus, home
# directory or host browser. Do not relabel the compositor's socket.
args+=(
--cap-add=SYS_CHROOT
--security-opt label=disable
--tmpfs "/run/media:rw,nosuid,nodev,size=1m,mode=1777"
--volume "$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY:/run/media/wayland-0:ro"
--env WAYLAND_DISPLAY=wayland-0
)
if [[ -S "$XDG_RUNTIME_DIR/pulse/native" ]]; then
args+=(
--volume "$XDG_RUNTIME_DIR/pulse/native:/run/media/pulse-native:ro"
--env PULSE_SERVER=unix:/run/media/pulse-native
)
fi
fi
exec podman --remote=false "${args[@]}" "localhost/ai-media-$app:managed" "$@"

View File

@@ -0,0 +1,7 @@
[Desktop Entry]
Type=Application
Name={{ 'FaceFusion' if item == 'facefusion' else 'RVC Voice Conversion' }} (offline)
Exec={{ user_home }}/.local/bin/ai-media {{ item }}
Terminal=false
Categories=AudioVideo;
StartupNotify=false

View File

@@ -0,0 +1,15 @@
*
!Containerfile.*
!prepare.py
!session.py
!verify.py
!requirements-facefusion.lock
!requirements-rvc.lock
!models/
{% for model in desktop_ai_media_public_models %}
!models/{{ model.app }}/
{% for depth in range(1, model.path.split('/') | length) %}
!models/{{ model.app }}/{{ model.path.split('/')[:depth] | join('/') }}/
{% endfor %}
!models/{{ model.app }}/{{ model.path }}
{% endfor %}