Skip to content

Instantly share code, notes, and snippets.

View robgon-art's full-sized avatar
😀

Robert A. Gonsalves robgon-art

😀
View GitHub Profile
@robgon-art
robgon-art / prompt.py
Created September 4, 2023 13:44
Prompt for Automatically Formatting Text into Markdowb
prompt = """You intelligently transform text files into markdown format.
From the content infer the following formats:
- Heading level 1
- Heading level 2
- Blockquotes
- Bullet lists
- Number lists
- Preformatted text
EXAMPLE TEXT
# robgonsalves
# Write some Python code to get ULRs to all images in my Flickr account.
# ChatGPT
# To get URLs to all images in your Flickr account, you can use the Flickr API and the flickr.photos.search method to retrieve the
# list of photos, and then construct the URLs based on the photo IDs and server IDs.
# Here's an example Python code that retrieves the URLs to all photos in your Flickr account using the flickrapi package:
import flickrapi
@robgon-art
robgon-art / repeat_edge_pixels.py
Created July 5, 2022 15:33
Change the aspect ratio of an image by repeating edge pixels
pil_image = Image.open("test.png").convert('RGB')
result = Image.new(pil_image.mode, (w_target, h_target))
pad_x = (w_target-w_source)//2
result.paste(pil_image, (pad_x, 0))
sample = 8
left_side = pil_image.crop((0, 0, sample, h_source))
left_side = left_side.resize((1, h_source//2), Image.BILINEAR)
left_side = left_side.resize((pad_x, h_source), Image.BILINEAR)
@robgon-art
robgon-art / create_gradient_image_with_clip.py
Last active July 16, 2022 04:20
create a gradient image with CLIP
# Copyright © 2022 Robert A. Gonsalves
# Released under CC BY-SA 4.0
# https://creativecommons.org/licenses/by-sa/4.0/
import torchvision.transforms as T
import torch
prompt = "penguins skiing down a snowy mountain"
num_steps = 100
init_rand_amount = 0.25
@robgon-art
robgon-art / pke_keyphrase_extraction.py
Created June 5, 2022 20:16
extract keyphrases using pke
import pke
extractor = pke.unsupervised.TopicRank()
num_keywords = 10
phrase = "penguins skiing down a snowy mountain"
extractor.load_document(input=phrase)
extractor.candidate_selection(pos={'NOUN', 'PROPN', 'ADJ', 'VERB'})
extractor.candidate_weighting()
@robgon-art
robgon-art / check_in_wiki.py
Created May 8, 2022 21:07
Check if a similar title exists in Wikipedia
import wikipedia
def check_in_wiki(name):
name_parts = name.split()
wiki_results = wikipedia.search(name)
for w in wiki_results:
w = w.lower()
match_all_parts = True
for n in name_parts:
n = n.lower()
if n == "the" or n == "a":
@robgon-art
robgon-art / get_friends_summaries_from_wikipedia.py
Created May 8, 2022 15:16
Get Friends Summaries from Wikipedia
import requests
from bs4 import BeautifulSoup
import pandas as pd
df_friends = pd.DataFrame(columns=["id", "title", "summary", "meta.season", "meta.episode"]).set_index("id")
for season in range(1, 11):
url = "https://en.wikipedia.org/wiki/Friends_(season_" + str(season) + ")#Episodes"
page = requests.get(url)
soup = BeautifulSoup(page.text, "html.parser")
from keybert import KeyBERT
kw_model = KeyBERT()
summary = "After leaving her fiancé, Barry, at the altar, Rachel finds herself in Central Perk Café, soaking wet in her wedding dress."
theme = kw_model.extract_keywords(summary, keyphrase_ngram_range=(1, 3))[0][0]
print(theme)
@robgon-art
robgon-art / texture.py
Created April 3, 2022 17:44
Generate texture for an image
from torchvision import transforms as T
import torch
texture_amount = 0.15
texture_size = 9
noise = torch.normal(0, texture_amount*texture_size**(1./3.),
size=[resized.shape[0], 1, resized.shape[2], resized.shape[3]]).to(device)
noise = noise.repeat(1, 3, 1, 1)
import wikipedia
print(wikipedia.search("Albert Einstein")[:5])
def check_in_wiki(name):
name_parts = name.split()
wiki_results = wikipedia.search(name)
for w in wiki_results:
w = w.lower()
match_all_parts = True
for n in name_parts: