Skip to content

Instantly share code, notes, and snippets.

@Norod
Norod / remove_nikud.py
Last active March 28, 2023 08:34
Input hebrew text with diacritics (Nikud / Niqqud) and output the same text without it
#pip install hebrew
import sys
from hebrew import Hebrew
def open_input_file_name(file_name):
try:
file = open(file_name, "r")
return file
except FileNotFoundError:
@Norod
Norod / multidiffusion_panorama_withqolupdatesbynorod78.ipynb
Created March 27, 2023 20:26
MultiDiffusion_Panorama_withQoLUpdatesByNorod78.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Norod
Norod / compare_cl100k_base_gpt2_hebrew_encoders.py
Created March 20, 2023 15:45
Compare encoded length of hebrew sentace between cl100k_base (GPT 3.5, 4) and gpt2 using OpenAI's tiktoken library
import tiktoken
test_string = "האיש האחרון עלי אדמות ישב לבד בחדרו, כשלפתע נשמעה דפיקה בדלת"
enc = tiktoken.get_encoding("cl100k_base")
encoded_text = enc.encode(test_string)
print(f'num of characters = {len(test_string)} encoded length = {len(encoded_text)} (cl100k_base)')
decoded_text = enc.decode(encoded_text)
assert decoded_text == test_string
@Norod
Norod / reset_and_update_existing_gdrive_fast_stable_diffusion_automatic1111.ipynb
Last active March 6, 2023 12:34
reset_and_update_existing_gdrive_fast_stable_diffusion_AUTOMATIC1111.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Norod
Norod / sd-diffusers-model-compare.py
Last active July 29, 2023 20:12
Compare two Stable-Diffusion diffuser models using a predifined set of prompts
from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler
import torch
#////////////////////////////////////////////////////////////////
guidance_scale=8.0
steps=40
width=512
height=512
@Norod
Norod / heb_eng_tokenize_compare.py
Created December 26, 2022 09:41
Compare the amount of tokens generated for a given Hebrew word input when an English and Hebrew tokenizers are used
from transformers import AutoTokenizer
tokenizer_heb = AutoTokenizer.from_pretrained("Norod78/hebrew-gpt_neo-small")
tokenizer_eng = AutoTokenizer.from_pretrained("gpt2")
prompt_text="שלום"
prompt_length = len(prompt_text)
encoded_prompt_heb = tokenizer_heb.encode(prompt_text, add_special_tokens=False, return_tensors="pt")
num_of_tokenz_heb = encoded_prompt_heb.size()[-1]
print(f"Hebrew tokenizer: Tokens = {num_of_tokenz_heb} length = {prompt_length}") #Hebrew tokenizer: Tokens = 1 length = 4
encoded_prompt_eng = tokenizer_eng.encode(prompt_text, add_special_tokens=False, return_tensors="pt")
@Norod
Norod / two_tigers-StableDiffusionDepth2ImgPipeline.py
Created December 9, 2022 17:15
The Huggingface example code for stabilityai/stable-diffusion-2-depth (with GPU, CPU and multiple image results)
import torch
import requests
from PIL import Image
from diffusers import StableDiffusionDepth2ImgPipeline
def main():
device = "cuda" if torch.cuda.is_available() else "cpu"
dtype = torch.float16 if device == "cuda" else torch.float32
pipe = StableDiffusionDepth2ImgPipeline.from_pretrained(
@Norod
Norod / 3d_object_to_images-cpu.ipynb
Created November 22, 2022 16:08
3d_object_to_images-CPU.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Norod
Norod / sd-simpsons-model-img2img.py
Last active December 1, 2022 11:33
Like the default HF StableDiffusion img2img sample, only it uses the sd2-simpsons-blip and DPMSolverMultistepScheduler
import requests
import torch
from PIL import Image
from io import BytesIO
from diffusers import StableDiffusionImg2ImgPipeline, DPMSolverMultistepScheduler
def main():
#////////////////////////////////////////////
seed = 42
@Norod
Norod / sd-simpsons-model-DPMSolverMultistepScheduler.py
Created November 10, 2022 20:31
Inference for sd-simpsons-model using DPMSolverMultistepScheduler
from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler
import torch
def main():
#////////////////////////////////////////////
seed = 42
model = "Norod78/sd-simpsons-model"
#////////////////////////////////////////////