This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
amount = 1.0 | |
img = Image.open("input_image.png") | |
image_np = np.array(img, dtype = np.float32) | |
gaussian = cv2.GaussianBlur(image_np, (0, 0), 1.0) | |
unsharp_image = cv2.addWeighted(image_np, 2.0, gaussian, -1.0, 0) | |
unsharp_image = amount * unsharp_image + (1.0 - amount) * image_np | |
image_int = unsharp_image.round().clip(0, 255).astype(np.uint8) | |
image_pil = Image.fromarray(image_int) | |
image_pil.save("output_image.png") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import numpy as np | |
from PIL import Image | |
img = Image.open("input_image.png") | |
image_np = np.array(img, dtype = np.float32) | |
dark_r = np.quantile(image_np[:,:,0:1], 0.1) | |
dark_g = np.quantile(image_np[:,:,1:2], 0.1) | |
dark_b = np.quantile(image_np[:,:,2:3], 0.1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import openai | |
openai.api_key = os.getenv("OPENAI_API_KEY") | |
response = openai.Completion.create( | |
engine="davinci-instruct-beta-v3", | |
prompt="Create prompts to render fictional people at different ages and nationalities.\n\n1. A watercolor painting", | |
temperature=0.7, | |
max_tokens=64, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
def inpaint(input_file_path, output_path): | |
!rm -r /content/input | |
!mkdir /content/input | |
!cp $input_file_path /content/input | |
parts = input_file_path.split("/") | |
mask_name = "/content/input/" + parts[-1] | |
mask_name = mask_name[:-4]+ "_mask.png" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a modified version of the find_faces code in DLIB, by Davis King | |
# The original version is here: | |
# https://github.com/davisking/dlib/blob/master/python_examples/face_recognition.py | |
import dlib | |
from PIL import Image | |
def find_faces(face_file_path): | |
# Load all the models we need: a detector to find the faces, a shape predictor | |
# to find face landmarks so we can precisely localize the face |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def rotate_points(x, y, x_axis_index, y_axis_index): | |
num_points = len(x) | |
x_rotated = [] | |
y_rotated = [] | |
x_axis_angle = math.atan2(y[x_axis_index], x[x_axis_index]) | |
y_axis_angle = math.atan2(y[y_axis_index], x[y_axis_index]) | |
if math.sin(y_axis_angle - x_axis_angle) < 0: | |
flip_y = -1.0 | |
else: | |
flip_y = 1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!python stylegan2/dataset_tool.py create_from_images 'datasets/paintings' 'paintings/' | |
!python stylegan2/run_training.py --config=config-e --metrics=none \ | |
--data-dir='/content/datasets' --dataset=paintings \ | |
--mirror-augment=true \ | |
--total-kimg=5000 \ | |
--result-dir='/content/drive/My Drive/results' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
index = random.randint(0, len(styles)-1) | |
style = styles[index].capitalize() | |
prompt = style + " painting" | |
r = random.random() | |
if r < 1.0/3.0: | |
series = "shapes" | |
index = random.randint(0, len(shapes)-1) | |
subject = " with " + shapes[index] | |
prompt += subject |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i, img in enumerate(all_images): | |
pil_image = PIL.Image.fromarray(img) | |
pil_image.save("/content/output/output_" + str(i) + ".png") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_warning_level(content_to_classify): | |
content_filter_results = openai.Completion.create( | |
engine="content-filter-alpha-c4", | |
prompt = "<|endoftext|>"+content_to_classify+"\n--\nLabel:", | |
temperature=0, | |
max_tokens=1, | |
top_p=1, | |
frequency_penalty=0, | |
presence_penalty=0, | |
logprobs=10) |