Spaces:
Running
Running
Update app.py
Browse files8 unmodified lines91011121314151617181920212223242526272829304 unmodified lines353637383940414243444546474849508 unmodified lines"nitrosocke/Arcane-Diffusion",safety_checker=None,)pipe.to("cuda")# 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 modelimage = load_image(frame_rgb)# Apply the anime-style transformationresult = pipe(prompt=prompt, image=image, strength=0.75).images[0]# Convert back to numpy arrayreturn np.array(result)# Function to convert the entire videodef video_to_anime(video_path, prompt="Arcane style"):# Read the input video using OpenCVcap = cv2.VideoCapture(video_path)fps = cap.get(cv2.CAP_PROP_FPS)frames = []4 unmodified linesframes.append(frame)cap.release()# Process each frame to anime styleprocessed_frames = [process_frame(frame, prompt) for frame in frames]# Write the output video using OpenCVheight, width, _ = processed_frames[0].shapefourcc = cv2.VideoWriter_fourcc(*'mp4v') # Codec for MP4output_path = "output.mp4"out = cv2.VideoWriter(output_path, fourcc, fps, (width, height))for frame in processed_frames:# Convert back to BGR for OpenCVframe_bgr = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)out.write(frame_bgr)out.release()8 unmodified lines9101112131415161718192021222324254 unmodified lines3031323334353637383940414243448 unmodified lines"nitrosocke/Arcane-Diffusion",safety_checker=None,)# Do NOT move to cuda; let it run on CPU by default# Function to process a single framedef process_frame(frame, prompt):frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)image = load_image(frame_rgb)result = pipe(prompt=prompt, image=image, strength=0.75).images[0]return np.array(result)# Function to convert the entire videodef video_to_anime(video_path, prompt="Arcane style"):cap = cv2.VideoCapture(video_path)fps = cap.get(cv2.CAP_PROP_FPS)frames = []4 unmodified linesframes.append(frame)cap.release()# Process each frameprocessed_frames = [process_frame(frame, prompt) for frame in frames]# Write the output videoheight, width, _ = processed_frames[0].shapefourcc = cv2.VideoWriter_fourcc(*'mp4v')output_path = "output.mp4"out = cv2.VideoWriter(output_path, fourcc, fps, (width, height))for frame in processed_frames:frame_bgr = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)out.write(frame_bgr)out.release()
app.py+4-10