Cog plays nicely with Jupyter notebooks, allowing you to develop and test your models interactively in the same environment defined by yourDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/replicate/cog/llms.txt
Use this file to discover all available pages before exploring further.
cog.yaml.
Setup
Running Jupyter Lab
Cog can run notebooks in the environment you’ve defined incog.yaml with the following command:
cog run- Runs the command in your Cog environment-p 8888- Exposes port 8888 for the Jupyter server--allow-root- Allows Jupyter to run as root (required in Docker)--ip=0.0.0.0- Makes Jupyter accessible from outside the container
Using Notebook Code in Your Predictor
You can import code from a notebook into your Cog predictor, enabling you to develop interactively and then productionize your work.Export your notebook to Python
Convert your notebook to a Python script:This creates a file called
my_notebook.py containing all the code from your notebook.Development Workflow
Here’s a recommended workflow for developing models with notebooks:- Start Jupyter Lab with
cog run -p 8888 jupyter lab --allow-root --ip=0.0.0.0 - Develop your model interactively in a notebook
- Test your model with sample data in the notebook
- Export the notebook to Python using
jupyter nbconvert - Import into predictor and define the prediction interface
- Test with Cog using
cog predict
Best Practices
Keep notebooks focused
Create separate notebooks for different stages of development:- Data exploration
- Model training
- Inference testing
Clean up before exporting
Before exporting a notebook:- Remove exploratory code and debug statements
- Ensure all imports are at the top
- Test that cells run in order from top to bottom
Version control
Consider adding both.ipynb and .py versions to version control:
- Notebooks for interactive development
- Python files for production code
Next Steps
- Learn about setting up your own model
- Explore the Python API reference
- See the cog.yaml reference for more configuration options