Skip to content

Instantly share code, notes, and snippets.

View simonw's full-sized avatar

Simon Willison simonw

View GitHub Profile
@simonw
simonw / mlx_whisper_realtime.py
Last active November 15, 2024 17:56 — forked from ivanfioravanti/mlx_whisper_realtime.py
mlx-whisper real time audio
# /// script
# dependencies = [
# "SpeechRecognition",
# "mlx-whisper",
# "pyaudio",
# ]
# ///
import speech_recognition as sr
import numpy as np
/**
* Creates a private GitHub Gist
* @param {string} description - Gist description
* @param {Object.<string, string>} files - Object with filenames as keys and content as values
* @param {string} token - GitHub Personal Access Token with gist scope
* @returns {Promise<Object>} - GitHub Gist API response object
* @throws {Error} - If the API request fails
*/
async function createPrivateGist(description, files, token) {
if (!token) {
import base64
import httpx
import llm
from PIL import Image
import io
@llm.hookimpl
def register_embedding_models(register):
@simonw
simonw / rag-demo.ts
Created June 20, 2024 17:17
Val.Town demo from this morning
import { basicAuth } from "https://esm.town/v/pomdtr/basicAuth?v=65";
import Anthropic from "npm:@anthropic-ai/[email protected]";
const anthropic = new Anthropic();
async function suggestKeywords(question) {
const message = await anthropic.messages.create({
max_tokens: 128,
model: "claude-3-5-sonnet-20240620",
tools: [{
"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[338],{578:(e,t,r)=>{e.exports=r.p+"7cf7ced34f0a1ece31b4.wasm"},338:(e,t,r)=>{var n;r.r(t),r.d(t,{default:()=>a});const a=(n="file:///private/tmp/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/emscripten-module.browser.mjs",function(e={}){var t,a,o=e;function i(e){e={log:e||function(){}};for(const t of i.za)t(e);return o.quickJSEmscriptenExtensions=e}o.ready=new Promise(((e,r)=>{t=e,a=r})),i.za=[],o.quickjsEmscriptenInit=i,i.za.push((e=>{e.getWasmMemory=function(){return Q}}));var _,u=Object.assign({},o),l="./this.program",s="object"==typeof window,f="function"==typeof importScripts,S="";(s||f)&&(f?S=self.location.href:"undefined"!=typeof document&&document.currentScript&&(S=document.currentScript.src),n&&(S=n),S=0!==S.indexOf("blob:")?S.substr(0,S.replace(/[?#].*/,"").lastIndexOf("/")+1):"",f&&(_=e=>{var t=new XMLHttpRequest;return t.open("GET",e,!1),t.responseType="arraybuffer",t.send(null),new Uint8Array(t.response)}));var c,T=o.print||con
@simonw
simonw / METADATA
Last active February 28, 2024 00:36
Flattened directory of the files from the whl for https://pypi.org/project/testcontainers-postgres
Metadata-Version: 2.1
Name: testcontainers-postgres
Version: 0.0.1rc1
Summary: PostgreSQL component of testcontainers-python.
Home-page: https://github.com/testcontainers/testcontainers-python
Requires-Python: >=3.7
Description-Content-Type: text/x-rst
Requires-Dist: testcontainers-core
Requires-Dist: sqlalchemy
Requires-Dist: psycopg2-binary
import sqlite3
# Connect to the test.db database
conn = sqlite3.connect(":memory:")
cursor = conn.cursor()
# Create the news table
cursor.execute(
"""
CREATE TABLE IF NOT EXISTS news (

I made this Toga app as a Bash one-liner:

python -c '
import toga
import urllib.request
import json

def fetch_json(url):
    with urllib.request.urlopen(url) as response:
 if response.getcode() == 200:
This file has been truncated, but you can view the full file.
BEGIN TRANSACTION;
CREATE TABLE [ios] (
[ios] TEXT,
[path] TEXT,
[parent] TEXT,
[filename] TEXT,
[languages] TEXT
);
INSERT INTO "ios" VALUES('iOS1','/Applications/Calculator.app/Calculator','/Applications/Calculator.app','Calculator','["Objective-C"]');
.grow-wrap {
/* easy way to plop the elements on top of each other and have them both sized based on the tallest one's height */
display: grid;
}
.grow-wrap::after {
/* Note the weird space! Needed to preventy jumpy behavior */
content: attr(data-replicated-value) " ";
/* This is how textarea text behaves */
white-space: pre-wrap;