Skip to content

Instantly share code, notes, and snippets.

View ddrscott's full-sized avatar

Scott Pierce ddrscott

View GitHub Profile
@ddrscott
ddrscott / txt2img.py
Last active February 20, 2024 22:20
Generate Image from Text using Together API Generate Image
#!/usr/bin/env python3
"""
Generate Image from Text using Together API Generate Image
## requirements.txt
click
requests
pillow
piexif
"""
@ddrscott
ddrscott / cf-gpt.sh
Created November 22, 2023 19:02
Cloudflare AI inference API
#!/bin/sh
# message can come from script args or environment
message=${message:-"${*}"}
model=${model:-"@cf/mistral/mistral-7b-instruct-v0.1"}
system=${system:-"You are a consice AI assistant. You help the user the best you can. If you don't know something, you admin it and ask clarifying questions. Use markdown as needed."}
post_data=$(cat <<JSON
{"messages":[{"role":"system","content":"${system}"},{"role":"user","content":"${message}"}],"max_tokens":10240,"stream":true}
JSON
)
#!/usr/bin/env python3
"""
Requirements:
pip install click langchain openai
Environment Variables:
OPENAI_API_KEY=...
"""
import sys
import click
@ddrscott
ddrscott / auto.py
Last active August 29, 2023 21:55
#!/usr/bin/env python3
"""
Requirements:
pip install click langchain openai
"""
import sys
import click
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
class CustomHandler(StreamingStdOutCallbackHandler):
def on_llm_start(self, serialized, prompts, **_) -> None:
import torchaudio
from speechbrain.pretrained import Tacotron2
from speechbrain.pretrained import HIFIGAN
# Intialize TTS (tacotron2) and Vocoder (HiFIGAN)
tacotron2 = Tacotron2.from_hparams(source="speechbrain/tts-tacotron2-ljspeech", savedir="tmpdir_tts")
hifi_gan = HIFIGAN.from_hparams(source="speechbrain/tts-hifigan-ljspeech", savedir="tmpdir_vocoder")
# Running the TTS
mel_output, mel_length, alignment = tacotron2.encode_text("This is an open-source toolkit for the development of speech technologies.")
(() => {
const className = 'dataturd-sidebar';
function openIframe(url) {
if ( document.querySelector('.' + className) ) {
console.log('Sidebar already exists');
return
}
var styleTag = document.createElement('style');

Prompt

I want to create a FFT visualization in a single page web app. Please separate the HTMLCSS in JavaScript. The canvas should fill up the entire bottom of the screen. Provide a button at the top to start and stop recording. The FFT should be based on web audio taking microphone recordings.

Code

<!DOCTYPE html>
<html>
  <head>
"""
Prompt: Help me create Python script to play connect four against a computer ai opponent.
"""
# Define the game board
board_rows = 6
board_cols = 7
# Define the evaluation function for the minimax algorithm
def evaluate_window(window, piece):
@ddrscott
ddrscott / Makefile
Created January 3, 2023 17:41
Compile a bunch of pixel art frames into an animated gif.
frames=$(shell ls -tr bouncing-ball/*.png)
bouncing-ball.gif: $(frames)
convert -delay 12 -loop 0 -dispose previous -resize 256x -filter Point $(frames) $@
(
(imgs, h) => imgs.forEach((i, idx) => {
let l = document.createElement('a');
l.href=i.src;
l.download=`image-${idx}.png`;
l.innerText=l.download;
h.appendChild(l)
})
)(
d.querySelectorAll("#jmuse-scroller-component img[alt]"),