in colab: # Cell 1: Setup environment !pip install torch==2.5.1 torchvision==0.20.1…
- User
in colab: # Cell 1: Setup environment !pip install torch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 --index-url https://download.pytorch.org/whl/cu124 !pip install xformers==0.0.28.post3 !apt install aria2 ffmpeg -qq
Cell 2: Clone repo and download weights
!git clone https://github.com/Francis-Rings/StableAnimator %cd StableAnimator
Download weights
...all aria2c commands here...
Fix antelopev2 folder bug:
!mv ./checkpoints/models/antelopev2/antelopev2 ./checkpoints/models/tmp !rm -rf ./checkpoints/models/antelopev2 !mv ./checkpoints/models/tmp ./checkpoints/models/antelopev2
Unzip inference samples:
!unzip ./checkpoints/inference.zip -d ./inference
Cell 3: Install python deps
!pip install diffusers transformers accelerate timm decord einops scipy pandas coloredlogs flatbuffers numpy packaging protobuf sympy imageio-ffmpeg insightface facexlib opencv-python-headless gradio onnxruntime-gpu
Cell 4: Define and load models, set device, then launch Gradio
(all python code from your notebook here, but reordered so globlas are initialized prior)
Make sure to move all model loading code inside if name == "main":
import torch import gradio as gr if name == "main": device = "cuda" if torch.cuda.is_available() else "cpu" dtype = torch.bfloat16 if device == "cuda" and torch.cuda.get_device_capability(0)[0] >= 8 else torch.float16
# load models, set attn processors, load weights, move to device demo.queue().launch(inline=False, share=True) - Assistant
Your Colab setup looks well-structured! A few general tips and a minimal example snippet to make sure everything runs smoothly in the last cell (
if __name__ == "__main__":block) and integrates with Gradio:
Key points:
- Use
if __name__ == "__main__":to avoid unintended execution when importing. - Set device and dtype early.
- Load your models inside that block.
- Initialize Gradio inside the block (e.g., define a simple demo function or your full app).
- Use
- User
add it to the code
- Assistant