transcriptor/generate-docker-compose.py
2025-03-20 15:13:12 +01:00

62 lines
1.9 KiB
Python

import json
import yaml
# Custom list class to force inline (flow style) YAML formatting
class InlineList(list):
pass
def inline_list_representer(dumper, data):
return dumper.represent_sequence('tag:yaml.org,2002:seq', data, flow_style=True)
yaml.add_representer(InlineList, inline_list_representer)
# Load the channels from channels.json
with open("channels.json", "r") as f:
channels = json.load(f)
compose = {
"services": {}
}
# For each channel, create a service entry
for channel in channels:
service_name = f"scanner_{channel['name']}"
compose["services"][service_name] = {
"image": "t0is/madmonq-transcriptor-image:cuda",
"environment": [
f"CHANNEL_NAME={channel['name']}",
f"CHANNEL_LANGUAGE={channel['language']}",
"TIMEDELTA_DAYS=10",
"TIMEDELTA_DAYS_EXACT=false",
"CLIP_CREATE_FROM_CHAT=false",
"TWITCH_CLIENT_ID=a0fuj6tm5ct79clvim9816orphqkov",
"TWITCH_CLIENT_SECRET=h7whj3yspxgj1909sgcafx6iz1p1es"
],
"volumes": [
"/shared/transcriptor/clips:/app/clips",
"/shared/transcriptor/vods:/app/vods",
"/shared/transcriptor/audio:/app/audio",
"/shared/transcriptor/chat:/app/chat",
"/shared/transcriptor/models:/app/models",
"/shared/transcriptor/transcripts:/app/transcripts"
],
"deploy": {
"resources": {
"reservations": {
"devices": [
{
"driver": "nvidia",
"count": "all",
"capabilities": InlineList(["gpu"])
}
]
}
}
}
}
# Write the docker-compose file
with open("docker-compose.yml", "w") as f:
yaml.dump(compose, f, default_flow_style=False)
print("docker-compose.yml generated successfully.")