Skip to content

Instantly share code, notes, and snippets.

View vaclavcadek's full-sized avatar

Václav Čadek vaclavcadek

  • Stealth
  • Prague, Czech Republic
View GitHub Profile
@vaclavcadek
vaclavcadek / svg_write_streamlit.py
Created April 7, 2021 13:30
How to write SVG file instead of broken (blurry) matplotlib.
def svg_write(fig, center=True):
"""
Renders a matplotlib figure object to SVG and embedd it as base64.
Disable center to left-margin align like other objects.
Shamelessly taken from:
https://discuss.streamlit.io/t/display-svg/172
"""
# Save to stringIO instead of file
imgdata = StringIO()
@vaclavcadek
vaclavcadek / dockerize.sh
Created May 14, 2021 11:38
Simple TF serving example with normalization layer being part of TF graph wrapped in TF serving REST API.
# Download the TensorFlow Serving Docker image and repo
docker pull tensorflow/serving
# Start TensorFlow Serving container and open the REST API port
docker run -t --rm -p 8501:8501 -v "/home/vaclav/PycharmProjects/the-algorithm-lab/tensorflow2/practice/deployment/my_model:/models/my_model" -e MODEL_NAME=my_model tensorflow/serving &
# Query the model using the predict API
curl -d '{"instances": [17.99000,20.57000,19.69000,11.42000,20.29000,12.45000,18.25000,13.71000,13.00000,12.46000,16.02000,15.78000,19.17000,15.85000,13.73000,14.54000,14.68000,16.13000,19.81000,13.54000,13.08000,9.50400,15.34000,21.16000,16.65000,17.14000,14.58000,18.61000,15.30000,17.57000]}' \
-X POST http://localhost:8501/v1/models/my_model:predict
@vaclavcadek
vaclavcadek / single_channel_ica.py
Created October 22, 2021 17:29
A not so successful attempt to perform single channel ICA using Wavelet Transform.
import itertools
from scipy import signal
import pywt
import numpy as np
import matplotlib.pyplot as plt
from sklearn.decomposition import FastICA
# #############################################################################
@vaclavcadek
vaclavcadek / memory_profiler.py
Created January 11, 2022 16:19
Simple snippet of how to profile memory in python.
import time
import gc
import psutil
import humanize
gc.collect()
time.sleep(2)
mem_before = psutil.virtual_memory()[3]
@vaclavcadek
vaclavcadek / Dockerfile
Last active November 4, 2024 12:31
FIPS enabled container to test FIPS compliance
# Dockerfile
FROM quay.io/centos/centos:stream9
# Enable better debugging
SHELL ["/bin/bash", "-x", "-c"]
# Install Python and required packages
RUN dnf update -y && \
dnf install -y python3 python3-pip openssl openssl-devel gcc python3-devel \
crypto-policies-scripts && \
@vaclavcadek
vaclavcadek / multi_status.py
Created February 21, 2025 21:26
Multistatus for asyncio tasks/gather.
from rich.console import Console, Group
from rich.live import Live
from rich.status import Status
import asyncio
import time
class MultiStatus:
def __init__(self, tasks):
self.statuses = {
name: Status(f"{name}: Starting...", spinner="dots", spinner_style="green")