CreatorPlus / creatorplus /services /diagnostics_service.py
Habib-HF's picture
Deploy CreatorPlus Docker Space
3311408 verified
Raw
History Blame Contribute Delete
1.96 kB
import os
import shutil
from pathlib import Path
from creatorplus.config import BASE_DIR, OUTPUTS_DIR, TEMP_DIR, UPLOADS_DIR
from creatorplus.services.media_service import test_media_provider_status
from creatorplus.services.tts_service import get_tts_provider_status
def _check_dir(path_obj):
path = Path(path_obj)
try:
path.mkdir(parents=True, exist_ok=True)
test_file = path / ".write_test"
test_file.write_text("ok", encoding="utf-8")
test_file.unlink(missing_ok=True)
return {"path": str(path), "ok": True}
except Exception as ex:
return {"path": str(path), "ok": False, "error": str(ex)}
def get_system_doctor(query="nature", aspect_ratio="9:16"):
ffmpeg_path = shutil.which("ffmpeg")
ffprobe_path = shutil.which("ffprobe")
folders = {
"base": _check_dir(BASE_DIR),
"outputs": _check_dir(OUTPUTS_DIR),
"temp": _check_dir(TEMP_DIR),
"uploads": _check_dir(UPLOADS_DIR),
}
media_status = test_media_provider_status(query=query, aspect_ratio=aspect_ratio)
tts_status = get_tts_provider_status()
env_summary = {
"PEXELS_API_KEYS_configured": bool(os.getenv("PEXELS_API_KEYS", "").strip()),
"PIXABAY_API_KEY_configured": bool(os.getenv("PIXABAY_API_KEY", "").strip()),
"COQUI_XTTS_MODEL": os.getenv("COQUI_XTTS_MODEL", "tts_models/multilingual/multi-dataset/xtts_v2"),
"PIPER_EXE": os.getenv("PIPER_EXE", ""),
"PIPER_MODEL_PATH": os.getenv("PIPER_MODEL_PATH", ""),
}
ready = bool(ffmpeg_path) and all(item.get("ok") for item in folders.values())
return {
"ok": True,
"ready": ready,
"binaries": {
"ffmpeg": ffmpeg_path,
"ffprobe": ffprobe_path,
},
"folders": folders,
"env": env_summary,
"tts": tts_status,
"media": media_status,
}