Skip to content

Instantly share code, notes, and snippets.

View luiscape's full-sized avatar
🤿

Luis Capelo luiscape

🤿
View GitHub Profile
@luiscape
luiscape / install_packages.sh
Created January 16, 2017 14:36
Install Python dependency packages from requirements.txt using conda.
#
# Original solution via StackOverflow:
# http://stackoverflow.com/questions/35802939/install-only-available-packages-using-conda-install-yes-file-requirements-t
#
#
# Install via `conda` directly.
# This will fail to install all
# dependencies. If one fails,
# all dependencies will fail to install.
@luiscape
luiscape / sd_torch_2_0.py
Created March 18, 2023 15:23
Stable Diffusion on PyTorch 2.0 (Modal)
# ## Basic setup
from __future__ import annotations
import io
import os
import time
from pathlib import Path
import modal
@luiscape
luiscape / mounting_hf_model.py
Created December 14, 2022 23:20
`modal.Mount` a HuggingFace model
import io
import time
import modal
import os
import torch
import diffusers
from pathlib import Path
stub = modal.Stub("local-model-mount-test")
@luiscape
luiscape / call_inside_modal.py
Created January 27, 2023 02:59
call_inside_modal.py
"""
Script to run batch inference using HuggingFace's zero-shot text-classification model on Modal.
Based on the tutorial: https://modal.com/docs/guide/ex/batch_inference_using_huggingface
Goal: filter a large Hugging Face dataset for food-related images (based on the text caption).
"""
import io
import modal
@luiscape
luiscape / batch_inference_modal.py
Created January 27, 2023 02:48
batch_inference_modal.py
"""
Script to run batch inference using HuggingFace's zero-shot text-classification model on Modal.
Based on the tutorial: https://modal.com/docs/guide/ex/batch_inference_using_huggingface
Goal: filter a large Hugging Face dataset for food-related images (based on the text caption).
"""
import io
import modal
@luiscape
luiscape / stable_diffusion_cli.py
Last active January 4, 2023 04:20
StableDiffusion NGC Containers on Modal
import io
import os
import time
from pathlib import Path
import modal
import typer
stub = modal.Stub("stable-diffusion-cli")
app = typer.Typer()
@luiscape
luiscape / diffusers-rs-on-modal.py
Last active January 4, 2023 03:33
Runs `diffusers-rs` on Modal.
# Runs diffusers-rs on Modal.
import os
import time
import modal
import subprocess
CARGO_PATH:str = "/root/.cargo/bin/cargo"
def _convert_clip():
@luiscape
luiscape / download_stable_diffusion_models.py
Last active November 29, 2022 00:05
Download Stable Diffusion + `EulerAncestralDiscreteScheduler` and store pipeline
"""This script downloads all neural networks used in the HuggingFace `diffuser`'s
`StableDiffusionPipeline` pipeline. This also downloads the parameters from the scheduler
`EulerAncestralDiscreteScheduler` because that is a fast and effective scheduler.
This requires the env var `HUGGINGFACE_TOKEN` to be populated with a HuggingFace
access token.
The default cache location is: /vol/cache. This can be changed by populating
the environment variable `CACHE_PATH`.
@luiscape
luiscape / jupyter_notebook_theme.sh
Created December 19, 2017 16:14
Install and configure Jupyter Themes.
#!/bin/bash
#
# Instally the theme library.
#
pip install jupyterthemes
#
# Configure to use preferred theme.
#
@luiscape
luiscape / plot_facets.py
Created December 11, 2017 17:20
Plots facets using Seaborn
#
# From Seaborn's official documentation:
#
# https://seaborn.pydata.org/generated/seaborn.FacetGrid.html
#
>>> import pandas as pd
>>> df = pd.DataFrame(
... data=np.random.randn(90, 4),
... columns=pd.Series(list("ABCD"), name="walk"),
... index=pd.date_range("2015-01-01", "2015-03-31",