Skip to content

Instantly share code, notes, and snippets.

@Norod
Norod / apple_openelm-3b_cuda_gradio-demo.ipynb
Created April 24, 2024 17:27
apple_OpenELM-3B_cuda_Gradio-Demo.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Norod
Norod / apple_openelm-270m_cpu_gradio-demo.ipynb
Created April 24, 2024 17:08
Apple_OpenELM-270M_cpu_Gradio-Demo.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Norod
Norod / onnx_rename_node_inp_inst.py
Created June 1, 2021 15:01
Rename a node in an ONNX model
import onnx
onnx_model = onnx.load('./input.onnx')
#Rename 'inp' to 'inst'
endpoint_names = ['inp', 'inst']
for i in range(len(onnx_model.graph.node)):
for j in range(len(onnx_model.graph.node[i].input)):
if onnx_model.graph.node[i].input[j] == endpoint_names[0]:
@Norod
Norod / heb_tokenize_compare.py
Created March 18, 2024 09:21
Compare Hebrew efficiency in various tokenizers (The lower the number, the better)
from transformers import AutoTokenizer
from transformers import LlamaTokenizerFast
#tokenizer_yam = AutoTokenizer.from_pretrained("yam-peleg/Hebrew-Gemma-11B-V2")
tokenizer_grok = LlamaTokenizerFast.from_pretrained('Xenova/grok-1-tokenizer')
tokenizer_gemma = AutoTokenizer.from_pretrained("google/gemma-7b-it")
tokenizer_aya101 = AutoTokenizer.from_pretrained("CohereForAI/aya-101")
tokenizer_gpt2 = AutoTokenizer.from_pretrained("gpt2")
@Norod
Norod / aya-101-gradio-with-streamer.py
Created March 15, 2024 11:22
A simple inference script for CohereForAI/aya-101 with Gradio based UI, RTL support and Streaming text
import torch
import gradio as gr
from threading import Thread
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, TextIteratorStreamer
checkpoint = "CohereForAI/aya-101"
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
model = AutoModelForSeq2SeqLM.from_pretrained(checkpoint, device_map='auto', torch_dtype=torch.bfloat16)
@Norod
Norod / colab-hebrewgpt-gradiodemo.ipynb
Last active March 7, 2024 08:30
colab-hebrewgpt-gradiodemo.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Norod
Norod / crapify_images.py
Created March 21, 2022 19:11
Go over a folder of images and reduce the quality and/or add noise to some of them (Useful for making a Pix2Pix model more resilient)
# crapify_images.py
# Go over a folder of images and reduce the quality and/or add noise to some of them (Useful for making a Pix2Pix model more resilient)
# @Norod78
import skimage
import skimage.io
import skimage.io._plugins.pil_plugin as pp
import numpy as np
from PIL import Image
To enhance readability, I'll add more line breaks within the sections to make the text easier to follow. Here's a revised version with additional spacing:
"You are ChatGPT, a large language model trained by OpenAI, based on the GPT-4 architecture."
"Image input capabilities: Enabled"
"Conversation start date: 2023-12-19T01:17:10.597024"
"Deprecated knowledge cutoff: 2023-04-01"
@Norod
Norod / README.MD
Last active January 24, 2024 20:57
Head Crop with Face Landmarks

Head Crop with Face Landmarks

This Python script utilizes the dlib library for face detection and facial landmarks to detect and crop a human head in an image. The detect_and_crop_head function takes an input image file, detects the face using a pre-trained 5-point facial landmarks model, and crops the image to include the entire head with a 1:1 aspect ratio. The cropping is adjusted based on the roll and yaw angles calculated from the facial landmarks.

Dependencies

  • Python 3
  • OpenCV
  • dlib
  • NumPy
@Norod
Norod / README.MD
Created December 14, 2023 09:15
Detect and Crop Head in Image

Detect and Crop Head in Image

This Python script leverages the OpenCV library for face detection and the PIL (Pillow) library for image processing to detect and crop a human head in an image. The detect_and_crop_head function takes an input image file, detects the face using a pre-trained Haar Cascade classifier, and crops the image to include the entire head with a 1:1 aspect ratio. The cropping is achieved by specifying a factor that determines the size of the cropped region around the detected face. Adjust the factor parameter based on the specific requirements of your images.

Usage:

input_image_path = "path/to/your/input/image.jpg"
output_image_path = "path/to/save/cropped/head.jpg"
detect_and_crop_head(input_image_path, output_image_path, factor=1.5)