Skip to content

Instantly share code, notes, and snippets.

View sborquez's full-sized avatar
🤖
AI means love in chinese

Sebastián Bórquez sborquez

🤖
AI means love in chinese
View GitHub Profile
@sborquez
sborquez / gradio_multipage.py
Created January 15, 2024 18:21
Gradio with multipage demos
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
import gradio as gr
app = FastAPI()
HELLO_ROUTE = "/hello"
GOODBYE_ROUTE = "/goodbye"
index_html = '''
@sborquez
sborquez / tar_image_iterator.py
Last active April 8, 2024 15:10
Load images from tar file without uncompress it
import io
from typing import Any, Callable, Iterator, Tuple, Union
import cv2
from google.cloud import storage
import numpy as np
from PIL import Image
import tarfile
@sborquez
sborquez / factory_registry.py
Last active May 16, 2023 00:59
A factory register pattern
import logging
from typing import Any, Dict, Type
class Registry:
"""
A factory register pattern
How to Use this Pattern
@sborquez
sborquez / dpython.sh
Last active May 10, 2022 16:27
Python bash wrappers
#!/bin/bash
# Add a timestamp to the python's output.
# Example:
# dpython -c "[print(i) for i in range(5)]"
# [2019-01-20 14:19:39] 0
# [2019-01-20 14:19:39] 1
# [2019-01-20 14:19:39] 2
# [2019-01-20 14:19:39] 3
# [2019-01-20 14:19:39] 4
# Setup:
@sborquez
sborquez / multi_producer_single_consumer.py
Last active May 10, 2022 16:34
Base code for a multi producer (worker) single consumer (writer) pattern.
from multiprocessing import Process, Manager, Pool
from multiprocessing.managers import AutoProxy
from typing import Any, List, Optional, Tuple
END_OF_QUEUE = None
class WorkersPool:
@sborquez
sborquez / hole_in_one.py
Last active December 9, 2020 17:21
Hole-in-one Python Code for a variety of classic CS problems
# FizzBuzz
print(*[(('','Fizz')[i%3==0] + ('','Buzz')[i%5==0]) if (i%3==0 or i%5==0) else i for i in range(1, 101)], sep="\n")
@sborquez
sborquez / split_tf_keras_models.py
Last active November 1, 2020 15:08
Split a trained tf_keras or keras model for predictions separatly.
from tensorflow.keras.models import Model
from tensorflow.keras.layers import Input
def split_model(model, split_layer_name=None, split_layer_index=None):
"""
Split a trained model for predictions.
If `split_layer_name` and `split_layer_index` are both provided, `split_layer_index` will take precedence.
Indices are based on order of horizontal graph traversal (bottom-up).
@sborquez
sborquez / TM-graph.yaml
Last active May 26, 2020 18:57
standard Turing Machine that decide the language of graph, with the format nodes#src1#dst1#src2#dst2.... in unary.
name: graph
source code: |-
#input: '111#1#11#11#11#1#111#111#11'
#input: '1#11'
input: '11#11#1'
#input: '11###1'
#input: '111'
blank: ' '
start state: check_zero_nodes
table:
@sborquez
sborquez / TM-binary_palindrome_enumerator.yaml
Last active May 18, 2020 01:04
This is a Turing Machine that lists L_B in canonical order. Where L_B is the set formed by all natural numbers whose representation in binary is a palindrome.
name: binary palindrome enumerator
source code: |
# Adds 1 to a binary number.
input: ''
blank: ' '
start state: setup_a
table:
# binary generator
setup_a:
' ' : {write: '#', L: setup_b}