Spaces:
Running
Running
Update app.py
Browse files8 unmodified lines9101112121314151616181720182219202122272324254 unmodified lines303132383334354136374338394041474243448 unmodified lines "nitrosocke/Arcane-Diffusion", safety_checker=None,)pipe.to("cuda")# Do NOT move to cuda; let it run on CPU by default
# Function to process a single framedef process_frame(frame, prompt): # Convert frame from BGR (OpenCV format) to RGB (expected by the model) frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) # Load the frame as an image for the diffusion model image = load_image(frame_rgb) # Apply the anime-style transformation result = pipe(prompt=prompt, image=image, strength=0.75).images[0] # Convert back to numpy array return np.array(result)
# Function to convert the entire videodef video_to_anime(video_path, prompt="Arcane style"): # Read the input video using OpenCV cap = cv2.VideoCapture(video_path) fps = cap.get(cv2.CAP_PROP_FPS) frames = []4 unmodified lines frames.append(frame) cap.release()
# Process each frame to anime style # Process each frame processed_frames = [process_frame(frame, prompt) for frame in frames]
# Write the output video using OpenCV # Write the output video height, width, _ = processed_frames[0].shape fourcc = cv2.VideoWriter_fourcc(*'mp4v') # Codec for MP4 fourcc = cv2.VideoWriter_fourcc(*'mp4v') output_path = "output.mp4" out = cv2.VideoWriter(output_path, fourcc, fps, (width, height)) for frame in processed_frames: # Convert back to BGR for OpenCV frame_bgr = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR) out.write(frame_bgr) out.release()app.py+4-10