Implement orphaned temporary folder re-import and resume feature with web UI modal
This commit is contained in:
+95
-1
@@ -1590,8 +1590,102 @@ def cleanup_temp(req: CleanupTempRequest):
|
||||
except Exception as e:
|
||||
errors.append(f"Error removing {path}: {str(e)}")
|
||||
|
||||
class ReimportTempRequest(BaseModel):
|
||||
video_path: str
|
||||
model: str = "realesrgan-x4plus"
|
||||
scale: int = 4
|
||||
tile_size: int = 256
|
||||
preserve_audio: bool = True
|
||||
ai_face_restoration: bool = False
|
||||
ai_rife_interpolation: bool = False
|
||||
ai_audio_denoise: bool = False
|
||||
ss: str | None = None
|
||||
t: str | None = None
|
||||
gpu_ids: str | None = None
|
||||
tta: bool = False
|
||||
unsharp: bool = False
|
||||
double_fps: bool = False
|
||||
preserve_subtitles: bool = True
|
||||
start_sec: float | None = None
|
||||
end_sec: float | None = None
|
||||
crf: int = 18
|
||||
preset: str = "medium"
|
||||
denoise: bool = False
|
||||
sharpen: bool = False
|
||||
interpolation: bool = False
|
||||
transcode_format: str = "mp4"
|
||||
temp_dir: str | None = None
|
||||
|
||||
@app.post("/api/system/temp-reimport/{job_id}")
|
||||
def reimport_temp(job_id: str, req: ReimportTempRequest):
|
||||
if job_id in jobs_db:
|
||||
raise HTTPException(status_code=400, detail="Job already exists in database.")
|
||||
|
||||
# Verify the video path is valid
|
||||
if not os.path.exists(req.video_path):
|
||||
raise HTTPException(status_code=400, detail=f"Video file not found at: {req.video_path}")
|
||||
|
||||
# Reconstruct the job dictionary
|
||||
job_dict = {
|
||||
"job_id": job_id,
|
||||
"video_path": req.video_path,
|
||||
"model": req.model,
|
||||
"scale": req.scale,
|
||||
"tile_size": req.tile_size,
|
||||
"preserve_audio": req.preserve_audio,
|
||||
"ai_face_restoration": req.ai_face_restoration,
|
||||
"ai_rife_interpolation": req.ai_rife_interpolation,
|
||||
"ai_audio_denoise": req.ai_audio_denoise,
|
||||
"ss": req.ss,
|
||||
"t": req.t,
|
||||
"gpu_ids": req.gpu_ids,
|
||||
"tta": req.tta,
|
||||
"unsharp": req.unsharp,
|
||||
"double_fps": req.double_fps,
|
||||
"preserve_subtitles": req.preserve_subtitles,
|
||||
"start_sec": req.start_sec,
|
||||
"end_sec": req.end_sec,
|
||||
"crf": req.crf,
|
||||
"preset": req.preset,
|
||||
"denoise": req.denoise,
|
||||
"sharpen": req.sharpen,
|
||||
"interpolation": req.interpolation,
|
||||
"transcode_format": req.transcode_format,
|
||||
"temp_dir": req.temp_dir,
|
||||
"status": "paused", # Start as paused so it can be resumed
|
||||
"progress": 0.0,
|
||||
"current_frame": 0,
|
||||
"total_frames": 0,
|
||||
"eta": "Ready to resume"
|
||||
}
|
||||
|
||||
job = upscaler.UpscaleJob.from_dict(job_dict)
|
||||
|
||||
# Calculate progress based on existing frames in the temp directory if possible
|
||||
job_temp_dir = os.path.join(req.temp_dir if req.temp_dir else upscaler.TEMP_DIR, job_id)
|
||||
input_frames_dir = os.path.join(job_temp_dir, "input_frames")
|
||||
output_frames_dir = os.path.join(job_temp_dir, "output_frames")
|
||||
|
||||
total_frames = 0
|
||||
if os.path.exists(input_frames_dir):
|
||||
total_frames = len([f for f in os.listdir(input_frames_dir) if f.startswith("frame_")])
|
||||
job.total_frames = total_frames
|
||||
|
||||
if os.path.exists(output_frames_dir):
|
||||
out_frames = len([f for f in os.listdir(output_frames_dir) if f.startswith("frame_")])
|
||||
job.current_frame = out_frames
|
||||
if total_frames > 0:
|
||||
job.progress = min(99.0, round((out_frames / total_frames) * 100.0, 2))
|
||||
|
||||
jobs_db[job_id] = job
|
||||
save_jobs_db()
|
||||
return {"cleaned": cleaned, "errors": errors}
|
||||
|
||||
# Auto-resume the job by adding it to the queue
|
||||
job_queue.put(job_id)
|
||||
job.update_status("queued", eta="Queued for resume...")
|
||||
save_jobs_db()
|
||||
|
||||
return {"status": "success", "job_id": job_id}
|
||||
|
||||
# ─── Distributed Processing Coordinator & Worker Endpoints ────────────────
|
||||
|
||||
|
||||
Reference in New Issue
Block a user