You can use this model to animate a portrait image by following the steps below:
-
Install required packages:
!pip install flask pyngrok
-
Clone the repository:
!git clone https://huggingface.co/codewithRiz/image-2-animation
-
Install the required dependencies:
!pip install -r /content/image-2-animation/requirements.txt
-
Set up the authentication token for Ngrok:
from pyngrok import ngrok
ngrok.set_auth_token("YOUR_NGROK_AUTH_TOKEN")
-
Initialize the model handler:
import sys
sys.path.append('/content/image-2-animation')
from handler import EndpointHandler
handler = EndpointHandler()
-
Upload the source image and driving video:
from google.colab import files
uploaded_files = files.upload() # This opens a file upload dialog
source_image = None
driving_video = None
for filename in uploaded_files.keys():
if filename.lower().endswith(('.jpg', '.jpeg', '.png')):
source_image = filename
elif filename.lower().endswith(('.mp4', '.avi')):
driving_video = filename
# Ensure both the image and video are uploaded
if not source_image:
print("Please upload a valid source image (jpg, png).")
sys.exit(1)
if not driving_video:
print("Please upload a valid driving video (mp4, avi).")
sys.exit(1)
-
Define input data for inference and run the model:
payload = {
"source": source_image, # Uploaded source image
"driving": driving_video # Uploaded driving video
}
response = handler(payload)
if 'output_path' in response:
output_path = response['output_path']
print(f"Inference completed. Output saved at: {output_path}")
# Download the output video
files.download(output_path) # Download the file to the user's machine
else:
print(response)