Skip to content

Instantly share code, notes, and snippets.

View pietz's full-sized avatar

Paul-Louis Pröve pietz

View GitHub Profile
@pietz
pietz / model.py
Created December 19, 2023 13:30
pydantic model for CV data extraction
class Job(BaseModel):
"""A Job or position extracted from the resume"""
position: str = Field(..., description="Name of the position")
company: str = Field(..., description="Company name")
start_date: str = Field(None, description="Start date of the job")
end_date: str = Field(None, description="End date of the job or 'Present'")
top_keywords: list[str] = Field(None, description="List of max. top 10 keywords, skills and technologies used for the job")
class Degree(BaseModel):
"""Degree or other type of education extracted from the resume"""
@pietz
pietz / schema.py
Created November 5, 2023 13:42
Create a Pydantic Model from a JSON schema
class Schema(BaseModel):
title: str = "Model"
type: Any
properties: Optional[dict[str, Any]]
required: Optional[list[str]]
items: Optional['Schema']
description: Optional[str]
@validator('type', pre=True)
def map_type(cls, v):
@pietz
pietz / main.py
Created June 4, 2023 15:52
Azure Function + FastAPI + ONNX
# __init__.py
# import logging
# import azure.functions as func
# from main.app import app
# def main(req: func.HttpRequest, context: func.Context) -> func.HttpResponse:
# logging.info("Python HTTP trigger function processed a request.")
# return func.AsgiMiddleware(app).handle(req, context)
@pietz
pietz / mlflow_score_script.py
Created July 22, 2022 07:07
Scoring script for Azure ML that can be used to run inference of mlflow models
import json
import logging
import numpy as np
import os
from copy import deepcopy
from inference_schema.parameter_types.abstract_parameter_type import AbstractParameterType
from inference_schema.parameter_types.numpy_parameter_type import NumpyParameterType
from inference_schema.parameter_types.standard_py_parameter_type import StandardPythonParameterType
from inference_schema.schema_decorators import input_schema, output_schema
import re
from unidecode import unidecode
def fingerprint(string):
# change all characters to their lowercase representation
string = string.lower()
# remove all punctuation and control characters
string = re.sub("[^A-Za-z0-9 ]+", "", string)
# normalize extended western characters to their ASCII representation
@pietz
pietz / draw_det.py
Created September 28, 2018 08:52
Take a YOLO style detection mask, convert it to a pixel mask and visualize it.
def draw_det(det, size=256):
g = float(len(det))
msk = np.zeros((size,size))
for col in range(det.shape[0]):
for row in range(det.shape[1]):
p,x,y,w,h = det[col,row]
if p > 0.5:
l = int(size*(col/g+x/g-w/2))
r = int(size*(col/g+x/g+w/2))
t = int(size*(row/g+y/g-h/2))
@pietz
pietz / unet-keras
Created April 14, 2017 09:51
U-Net model for Keras
from keras.models import Input, Model
from keras.layers import Conv2D, Concatenate, MaxPooling2D, Reshape
from keras.layers import UpSampling2D, Dropout, Activation, Permute
def level_block(m, dim, depth, acti):
if depth > 0:
n = Conv2D(dim, (3, 3), activation=acti, padding='same')(m)
n = Conv2D(dim, (3, 3), activation=acti, padding='same')(n)
m = MaxPooling2D((2, 2))(n)
m = level_block(m, 2*dim, depth-1, acti)

Keybase proof

I hereby claim:

  • I am pietz on github.
  • I am pietz (https://keybase.io/pietz) on keybase.
  • I have a public key whose fingerprint is B668 2EB3 A046 60D6 F991 E6D5 5257 CB68 A459 B6C5

To claim this, I am signing this object: