Skip to content

Instantly share code, notes, and snippets.

t -> the
o -> of
a -> and
i -> in
to -> to
w -> was
is -> is
f -> for
on -> on
as -> as
import json
# word_frequency.txt contains one word per line, most common words first
with open("word_frequency.txt","r",encoding="utf-8") as f: words = f.read().splitlines()
wrds = set()
wrds_list = []
wrds_learn = []
for word in words:
@avelican
avelican / main.py
Created April 12, 2023 19:25
SemiAuto for GPT (draft)
from semiauto import search, load, summarize, save
"""
Run Query
Extract links
for each link:
get text, title etc
summarize text based on goal (extract desired info)
NOTE: need to build a recursive summarizer
splitting based on paragraphs (+ a few extra before and after) will give superior results.
@avelican
avelican / main.py
Created April 14, 2023 12:39
GPT-powered text search
# NOTE: Ensure folders 'input' and 'output' exist in script folder.
import os
import openai
import sys
openai.api_key = os.getenv("OPENAI_API_KEY")
OPENAI_MODEL="text-davinci-003"
# OPENAI_MODEL="text-curie-001"
@avelican
avelican / main.py
Created April 14, 2023 15:56
Accio (GPT powered text file search with PDF support)
import os
import openai
import sys
from pdfminer.high_level import extract_text # pip install pdfminer.six
openai.api_key = os.getenv("OPENAI_API_KEY")
OPENAI_MODEL="text-davinci-003"
# OPENAI_MODEL="text-curie-001"
# OPENAI_MODEL="text-babbage-001"
@avelican
avelican / PyGPT_prompt_WIP.txt
Created April 19, 2023 19:43
PyGPT prompt (WIP)
You are part of an automated system. You must respond only in JSON.
If you need more information about a file, function or class, use one of the "read" actions first.
If you use a read action, do not use any write actions yet, because you will receive a response with the result of the read action.
This will allow you to make better decisions.
If you use one of the "replace" methods, e.g. replace_function_body, you must include the WHOLE function in the content field. Do not omit code: the project will be corrupted!
If you are unable to complete the task with the available actions, use the talk action to explain why. We will use this feedback to improve the system.
Read Actions:
file_read
read_function
@avelican
avelican / keypoints.py
Created April 26, 2023 23:04
Keypoints.py - Summarize a long text document to bullet points
import os
import openai
prompt = "I'm a busy CEO, please summarize the following in 10-20 bullet points. Include only the most important, useful or interesting information.\n\n"
# model = 'gpt-3.5-turbo' # 'gpt-4' # moved to gpt_chat_completion since we use both
CONTEXT_SIZE = 4096 # 2048 for GPT-3 (as half the input.
# CONTEXT_SIZE = 1024 # tiny context for testing
MAX_TOKENS_IN = int(CONTEXT_SIZE*2/3)
MAX_TOKENS_OUT = CONTEXT_SIZE - MAX_TOKENS_IN
@avelican
avelican / yt-txt.py
Created April 30, 2023 08:19
Get YouTube transcript (from subtitles / caption file)
import sys
import subprocess
if len(sys.argv) < 2:
print("Please provide a YouTube video URL as the first argument.")
sys.exit(1)
video_url = sys.argv[1]
command = [
@avelican
avelican / gpt-async.py
Created May 1, 2023 10:26
Parallelize GPT API
# import openai
import os
import asyncio
import aiohttp
import random
OPENAI_API_KEY = os.environ['OPENAI_API_KEY']
@avelican
avelican / stereo.py
Created May 7, 2023 18:28
autostereogram generator
# credit goes to https://github.com/synesthesiam/magicpy
# Instructions: Texture image MUST be as tall as depth map (taller should work too),
# and 1/8th of its width (or thereabouts -- any width will work but might not look too good).
from PIL import Image
if __name__ == '__main__':
depth_file = "depth.jpg"