Skip to content

Instantly share code, notes, and snippets.

@tiny-rawr
tiny-rawr / get_intercom_convo_history.py
Last active January 23, 2025 03:50
Get last 6 months of conversation history from intercom. It saves all conversation ids to a python file. Then uses each id to get the conversation. Then we extract the data we want and do some clean up like extracting images and removing html from the responses.
import requests
from dotenv import load_dotenv
import os
import csv
from conversation_ids import conversation_ids
from bs4 import BeautifulSoup
from concurrent.futures import ThreadPoolExecutor, as_completed
load_dotenv()
@tiny-rawr
tiny-rawr / ble_light_remote
Created January 12, 2025 02:22
Control multiple bluetooth low energy (BLE) smart lights from different manufacturers in a single script. You'll need to change the device address, characteristic UUIDs and values to match your own lights.
import asyncio
from bleak import BleakScanner, BleakClient
import subprocess
from abc import ABC, abstractmethod
# Base class for your lights (enables polymorphism)
# So each light responds to same command but implements differently
class BLELight(ABC):
def __init__(self, address, characteristic_uuid):
self.address = address
@tiny-rawr
tiny-rawr / youtube_video_transcript.txt
Last active April 12, 2024 08:01
Get transcript from a single YouTube video
# pip install youtube-transcript-api
from youtube_transcript_api import YouTubeTranscriptApi
def get_video_transcript(video_id="wk89rJpaj6w"):
transcript_with_timestamps = YouTubeTranscriptApi.get_transcript(video_id)
transcript = ' '.join([t['text'] for t in transcript_with_timestamps])
return transcript
print(get_video_transcript())
@tiny-rawr
tiny-rawr / gist:eaed29c8589f2422da327e8fc32dd893
Created March 24, 2024 00:37
Retrieve data from AirTable (optional view)
def get_airtable_data(view_name=None, table_name="Members"):
print("getting members")
access_token = st.secrets["airtable"]["personal_access_token"]
url, headers = f"https://api.airtable.com/v0/appnc2IWGpsHNfTvt/{table_name}", {"Authorization": f"Bearer {access_token}"}
params = {} if view_name is None else {"view": view_name}
data = []
while True:
res = requests.get(url, headers=headers, params=params).json()
data += res.get('records', [])
if 'offset' not in res: break
@tiny-rawr
tiny-rawr / gist:d7fb36a49d6a7b64da81d471fb752835
Created March 24, 2024 00:10
React example of Mixpanel
import React, { useEffect, useState } from 'react';
import mixpanel from 'mixpanel-browser';
const ThoughtChecker = () => {
const [textEntered, setTextEntered] = useState(false);
const [journalText, setJournalText] = useState('');
const [defaultJournalEntry, setDefaultJournalEntry] = useState(''); // Set your default journal entry here
const sessionID = ''; // Set your session ID here
useEffect(() => {
@tiny-rawr
tiny-rawr / gist:4a51fc1a1180eb03b6e8e6bd4e8a7272
Created February 1, 2024 05:13
Generate talking avatar video from image and audio file with GooeyAI
import requests
import json
def generate_talking_avatar(image_filepath, audio_filepath):
api_key = "<YOUR_API_KEY>"
files = [
("input_face", open(image_filepath, "rb")),
("input_audio", open(audio_filepath, "rb")),
]
@tiny-rawr
tiny-rawr / gist:79d7ffd5cd34d96b993ac4bb07166e6c
Last active February 1, 2024 04:32
Text-to-speech with OpenAI's TTS model
from openai import OpenAI
def choose_voice(gender="female")
gender = gender.lower()
voice = "shimmer" # gender neutral
if gender == "female":
voice = "nova"
elif gender == "male":
voice = "onyx"
@tiny-rawr
tiny-rawr / gist:1efc2a0cc4801eb460adcabb576bd128
Created January 29, 2024 07:35
Generate a simple text chatbot (1-3 sentence response) with OpenAI's GPT-3.5-Turbo model
from openai import OpenAI
def respond_to_message(message, character_description):
api_key = st.session_state.api_key
client = OpenAI(api_key = api_key)
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": f"You are a helpful assistant. Respond to the following message in 1-3 sentences. Also, this is a description of the character you are in case you are asked: {character_description}"},
@tiny-rawr
tiny-rawr / gist:ad523bcf3fbe0e2781c81567eec3daf3
Last active January 29, 2024 07:27
Generate a custom character image with OpenAI's DALLE 3
from openai import OpenAI
def create_custom_character(character_description):
client = OpenAI(api_key=api_key)
response = client.images.generate(
model="dall-e-3",
prompt=f"Please create the following 3D character in the style of Pixar Animation Studio with a blurred sunlight background: {character_description}. There should be no text in the image.",
size="1024x1024",
@tiny-rawr
tiny-rawr / categorise_cognitive_distortions
Created December 12, 2023 06:37
Categorise and explain cognitive distortions using OpenAI Chat Completion model with function calling.
def categorise_cognitive_distortions(quotes):
client = OpenAI()
client.api_key = st.session_state.api_key
conversation = [
{"role": "system",
"content": "You categorise cognitive distortions and explain why they are an example of that cognitive distortion"},
{"role": "user", "content": str(quotes)},
]
response = client.chat.completions.create(