import json import logging import shutil import time import uuid from pathlib import Path from runtime import ROOT, MODEL_ROOT, configure_storage, startup_checks configure_storage() logging.basicConfig(filename=ROOT/"logs/workflow.log",level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s") runtime_report = startup_checks() import gradio as gr import torch import trimesh from preflight import inspect_glb import upstream.app as mia mia.init_models() # Initialize existing upstream component references used by its workflow. # The original UI is not launched. upstream_blocks = mia.init_blocks() print("MODELS_READY dedicated CUDA inference",flush=True) def preserve_and_inspect(path): if not path: raise gr.Error("Upload a GLB first.") folder = ROOT/"inputs"/uuid.uuid4().hex folder.mkdir() original = folder/"original.glb" shutil.copyfile(path,original) try: report = inspect_glb(original) except (ValueError,KeyError,IndexError,TypeError) as exc: report = {"inference_allowed":False,"warning":"Invalid or unsupported GLB: "+str(exc)} report.update(original=str(original),cuda_available=torch.cuda.is_available(),gpu=runtime_report["gpu"]) (folder/"preflight.json").write_text(json.dumps(report,indent=2)) return str(original),report,str(original) def execute(original,report): if not original or not report or not report.get("inference_allowed"): raise gr.Error((report or {}).get("warning") or "Inspect an eligible GLB before inference.") if not torch.cuda.is_available(): raise gr.Error("CUDA is unavailable; CPU inference is disabled.") # Recheck the preserved file before expensive processing. checked=inspect_glb(original) if not checked["inference_allowed"]: raise gr.Error(checked["warning"]) job=ROOT/"outputs"/uuid.uuid4().hex job.mkdir() working=job/"character.glb" shutil.copyfile(original,working) db=mia.DB() started=time.time() stages=("Loading mesh","Preparing coordinates","Predicting skeleton and weights", "Preparing rest pose","Exporting rigged asset","Finishing") try: for stage,_ in zip(stages,mia._pipeline(input_path=str(working),db=db, reset_to_rest=True,rest_pose_type=None)): yield stage,None,None,None for p in (db.anim_path,db.anim_vis_path): if not p or not Path(p).is_file() or Path(p).stat().st_size==0: raise RuntimeError("Upstream export did not produce a nonempty asset") # Validate export parsing without changing it. result=trimesh.load(db.anim_vis_path,force="scene",process=False) if not result.geometry: raise RuntimeError("Exported GLB contains no geometry") with open(db.anim_vis_path,"rb") as stream: import struct stream.seek(12) length,kind=struct.unpack("