Log into your server with ssh, something like
ssh -i "my_secret.pem" [email protected]
If it's a new server, you'll need to install a few things.
Install conda with
# Quick snippet to connect to a Jupyter notebook server running inside a Modal container, | |
# especially useful for exploring the contents of Modal shared volumes. | |
# This uses https://github.com/ekzhang/bore to expose the server to the public internet. | |
# | |
# Steps | |
# ----- | |
# 1. (Recommended) Change `JUPYTER_TOKEN` to a different value; default is 1234. | |
# 2. `modal run jupyter-bore.py` | |
# 3. Find the `bore.pub` URL printed in the logs, and navigate to it using your browser. |
import torch | |
from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler | |
import matplotlib.pyplot as plt | |
from PIL import Image | |
import numpy as np | |
plt.rcParams["figure.figsize"] = (10,5) | |
plt.rcParams['figure.facecolor'] = 'white' | |
def generate_tuxedo_cat_picture(fn_prefix, seed=0): |
# Source: https://stackoverflow.com/a/33597599/5391200 | |
from pylab import * | |
cmap = cm.get_cmap('seismic', 5) # matplotlib color palette name, n colors | |
for i in range(cmap.N): | |
rgb = cmap(i)[:3] # will return rgba, we take only first 3 so we get rgb | |
print(matplotlib.colors.rgb2hex(rgb)) | |
cmap = cm.get_cmap('plasma', 101) |
from PIL import Image, ImageOps | |
def padding(img, expected_size): | |
desired_size = expected_size | |
delta_width = desired_size - img.size[0] | |
delta_height = desired_size - img.size[1] | |
pad_width = delta_width // 2 | |
pad_height = delta_height // 2 | |
padding = (pad_width, pad_height, delta_width - pad_width, delta_height - pad_height) |
Log into your server with ssh, something like
ssh -i "my_secret.pem" [email protected]
If it's a new server, you'll need to install a few things.
Install conda with
""" | |
Produces load on all available CPU cores. | |
Requires system environment var STRESS_MINS to be set. | |
""" | |
from multiprocessing import Pool | |
from multiprocessing import cpu_count | |
import time | |
import os |
#!/bin/env python | |
# Requires: youtube_dl module | |
# Requires: ffmpeg | |
# Usage: | |
# | |
# python youtube2mp3.py <URL>, ... | |
# | |
# Example: | |
# | |
# python youtube2mp3.py https://www.youtube.com/watch?v=dQw4w9WgXcQ |
def calc_lift(x,y,clf,bins=10): | |
""" | |
Takes input arrays and trained SkLearn Classifier and returns a Pandas | |
DataFrame with the average lift generated by the model in each bin | |
Parameters | |
------------------- | |
x: Numpy array or Pandas Dataframe with shape = [n_samples, n_features] | |
y: A 1-d Numpy array or Pandas Series with shape = [n_samples] |
ipython nbconvert --to markdown <notebook>.ipynb --config jekyll.py |