Skip to content

Instantly share code, notes, and snippets.

View dmarx's full-sized avatar

David Marx dmarx

View GitHub Profile
@dmarx
dmarx / arxiv2markdown.py
Last active April 3, 2024 15:36
will not work on newest articles because ar5iv is not indexed live (yet). At present, two weeks lag.
# NB: ar5iv endpoint is lagged relative main arxiv
import subprocess
def convert_arxiv_url_to_markdown(arxiv_url, target_format='markdown_github'):
parts = arxiv_url.split('/')
article_id = parts[-1] if parts[-1] else parts[-2] # Account for trailing slash
article_id = article_id.replace('.pdf', '')
html_url = f'https://ar5iv.labs.arxiv.org/html/{article_id}'
@dmarx
dmarx / infinite-honk.prompt
Last active February 10, 2024 07:19
infinite-craft: the honkening
simulate the behavior of the following function. respond only with the output, enclosed in brackets.
def pair(node1, node2):
GeeseGraph = WorldGraph.neighborhood("things related to geese")
geese_nodes1 = GeeseGraph.nearest_neighbors(node1, n=10)
geese_nodes2 = GeeseGraph.nearest_neighbors(node2, n=10)
return geese_nodes1.intersect(geese_nodes2).sample(n=1, bias="funny matches")
>>> GeeseGraph.sample(n=100)
[pond, goose, feather, honk, migration, flock, nest, lake, wintering grounds, birdwatching, grain, park, bread, gosling, water, flyway, wetlands, grass, reeds, sunrise, sunset, quack, wildlife, bird, aviary, down, flapping, waddle, pecking, squawk, preen, aquatic plants, river, stream, marsh, ecosystem, habitat, conservation, ornithology, species, biodiversity, nature reserve, environmental protection, tagging, tracking, molting, territorial, aggression, mating rituals, offspring, survival, adaptation, plumage, waterfowl, aquatic invertebrates, feeding, foraging, resting, roosting, territo
@dmarx
dmarx / HawkesProcess.py
Created January 30, 2024 23:00
Hawkes Process Simulation
import numpy as np
import scipy as sp
from scipy.stats import poisson, expon
import matplotlib.pyplot as plt
import math
import random
random.seed(42)
@dmarx
dmarx / monte-carlo-contrastive-loss.py
Last active November 15, 2023 17:18
no idea if this would work, just sketching out the idea
eff_batch_size=2048
#########################
# what you're doing-ish #
#########################
gradient_accumulation_steps = 4
micro_batch_size = eff_batch_size // gradient_accumulation_steps
@dmarx
dmarx / comfyui-in-jupyter-notebook.py
Created November 9, 2023 19:35
MWE demonstrating how to use ComfyUI nodes programmatically
def init_comfy(
comfyui_path = "/home/dmarx/projects/ComfyUI"
):
# 1. add ComyUI to path
import sys
sys.path.append(comfyui_path)
# 2. ensure cli parser doesn't cause issues
from comfy.options import enable_args_parsing
enable_args_parsing(False)
#!pip install omegaconf keyframed
from omegaconf import OmegaConf
from collections import defaultdict
from keyframed import Curve
from keyframed.dsl import curve_from_cn_string
from keyframed.utils import simplify
def update_storyboard_inferred_values(storyboard):
@dmarx
dmarx / symlink_reversi.py
Created February 24, 2023 17:03
adds symlinks to existing frames in reverse order to facilitate compiling bounce-looped videos.
@dmarx
dmarx / moar.yaml
Last active February 9, 2023 18:38
putting this in a gist so I don't have to keep looking for it. via: https://discord.com/channels/869630568818696202/899135695677968474/943391522353721384
scene1 {transition: t0} | scene2 {transition: t1} | scene3 {transition: t0} | scene4
scenes:
scene1:
prompts:
- foo
- bar
scene2:
prompts:
- baz
@dmarx
dmarx / ldm_config_utils.py
Created January 24, 2023 23:34
instantiate_from_config implementation used by CompVis
# via https://github.com/Stability-AI/stablediffusion/blob/main/ldm/util.py
def instantiate_from_config(config):
if not "target" in config:
if config == '__is_first_stage__':
return None
elif config == "__is_unconditional__":
return None
raise KeyError("Expected key `target` to instantiate.")
return get_obj_from_str(config["target"])(**config.get("params", dict()))
@dmarx
dmarx / exif.py
Created January 19, 2023 04:23
code snippets for getting useful exif metadata from generative art outputs
###############
# DreamStudio #
###############
import PIL
from PIL import Image, ExifTags
def get_exif(img):
outv = {}
for k, v in img.getexif().items():