Skip to content

Instantly share code, notes, and snippets.

View izikeros's full-sized avatar

Krystian Safjan izikeros

View GitHub Profile
@izikeros
izikeros / progress_bar.py
Last active March 14, 2024 09:51
[simple progress bar] Simple, text-based progress bar #python
# Print iterations progress
# from: https://gist.github.com/aubricus/f91fb55dc6ba5557fbab06119420dd6a
def print_progress(iteration, total, prefix="", suffix="", decimals=1, bar_length=100):
"""Call in a loop to create terminal progress bar.
@params:
iteration - Required : current iteration (Int)
total - Required : total iterations (Int)
prefix - Optional : prefix string (Str)
@izikeros
izikeros / python_wrap_text.py
Created December 24, 2023 05:20
python wrap text
from textwrap import fill
text = 30 * "Hello world! "
print(fill(text, width=80))
@izikeros
izikeros / .editorconfig
Last active March 14, 2024 09:56
[.editorconfig file] .editorconfig #qa #project #configuration
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
max_line_length = 120
tab_width = 4
@izikeros
izikeros / README.md
Last active December 16, 2023 03:22
Install package in colab and jupyter notebook

Installation of Git Packages for Jupyter and Google Colab

This README will guide you through the process of installing packages directly from a Git repository in a way that is compatible with both Google Colab and Jupyter Notebooks. The provided code will attempt to execute compatible commands depending on the running environment.

Workflow Explanation

Extension Loading:

%load_ext autoreload
@izikeros
izikeros / text_perplexity.py
Last active March 14, 2024 09:59
[perplexity calculation] Text perplexity calculation #llm
# gist for the blog post on https://safjan.com
import tiktoken
import math
# Exemplary text
text = "Another vital aspect to consider in the realm of text generation is perplexity. Essentially, perplexity refers to the amount of information contained within a text. Natural language possesses a remarkable redundancy that enables effective communication, even in noisy environments such as a crowded bar or an intimate dinner. This redundancy allows for the overall message to be comprehended, even if certain parts of the text are missing or obscured."
# Tokenize the text using tiktoken
tokens = tiktoken.tokenize(text)
@izikeros
izikeros / README.md
Last active July 4, 2023 03:27
Bash script that calls the Azure OpenAI API to ask a question and returns the answer

ask_gpt.sh

A script to call the Azure OpenAI API and ask a question, returning the answer.

Description

ask_gpt.sh is a Bash script that interacts with the Azure OpenAI API to ask a question and retrieve the corresponding answer. It simplifies the process of making API calls and handling the JSON response.

Usage

@izikeros
izikeros / README.md
Last active March 26, 2024 18:11
[split text fixed tokens] Split text into parts with limited length in tokens #llm #tokens #python

Text Splitter

Code style: black MIT license

A Python script for splitting text into parts with controlled (limited) length in tokens. This script utilizes the tiktoken library for encoding and decoding text.

Table of Contents

@izikeros
izikeros / odsetki_ustawowe.py
Last active March 15, 2023 15:56
skrypt obliczający odsetki ustawowe od należności podanych w pliku csv
"""
Skrypt obliczający odsetki ustawowe od należności podanych w pliku csv
Przykladowa zawartość pliku:
required_payment_date,payment_amount
2023-02-10,2700
2023-03-10,1200
"""
@izikeros
izikeros / 2023_astro_pi_zero_konspekt.md
Created March 10, 2023 07:25
Konspekt przeprowadzenia AstroPi misja zero
@izikeros
izikeros / T_SNE_demo.py
Created February 20, 2023 13:31
T-SNE demo (2D, 3D)
import numpy as np
from sklearn.manifold import TSNE
from plotly import graph_objs as go
# generate 10-dimensional data
X = np.random.rand(100, 10)
print(X.shape)
# reduce to 3 components
X_embedded = TSNE(n_components=3).fit_transform(X)