Skip to content

Instantly share code, notes, and snippets.

View xhluca's full-sized avatar
💭
🔨

Xing Han Lu xhluca

💭
🔨
View GitHub Profile
/* monochrome theme */
/* Colors */
/* Typography */
/* Borders */
/* Shadows */
/* Layout */
body {
user-select: none;
background: #000;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@xhluca
xhluca / svg_to_plotly_fig.py
Last active July 17, 2020 02:08
A simple function for converting a SVG file to plotly
import base64
import xml
import plotly.graph_objects as go
def svg_to_fig(svg_bytes, title=None, plot_bgcolor='white', x_lock=False, y_lock=False):
svg_enc = base64.b64encode(svg_bytes)
svg = f'data:image/svg+xml;base64, {svg_enc.decode()}'
# Get the width and height
xml_tree = xml.etree.ElementTree.fromstring(svg_bytes.decode())
@xhluca
xhluca / app.py
Last active November 5, 2020 16:43
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import plotly.express as px
import pandas as pd
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
@xhluca
xhluca / speech_synthesis_app.py
Created May 21, 2020 19:16
Dash Text to Speech
# -*- coding: utf-8 -*-
"""
Speech Synthesis with Dash. This will only work with a Nvidia GPU.
Requirements (put them in requirements.txt):
apex
dash
numpy
scipy
tensorflow
numpy
pandas
matplotlib
scikit-learn
jupyter
jupyterlab
seaborn
@xhluca
xhluca / ml_bundle.txt
Last active January 17, 2020 22:48
Popular libraries for ML (no DL included). I use this when I get a clean installation of conda.
# Short link: http://bit.ly/python-ml-bundle
# Usage (after creating a venv or conda env):
# wget http://bit.ly/pip-ml-bundle
# pip install -r pip-ml-bundle
# rm pip-ml-bundle
# scientific
numpy
scipy
@xhluca
xhluca / TFRidge.py
Last active June 27, 2019 21:05
A faster implementation of scikit-learn's Ridge, leveraging Tensorflow: https://www.kaggle.com/xhlulu/accelerate-sklearn-regression-using-tensorflow
import numpy as np
import tensorflow as tf
class TFRidge:
def __init__(self, alpha=1.0, fit_intercept=True, normalize=False, solver='cholesky'):
if solver != 'cholesky':
raise ValueError('The only accepted solver is currently "cholesky"')
self.alpha = alpha
self.fit_intercept = fit_intercept
%% md
# Scikit-Learn in the browser: Iris Classification
The goal of this notebook is to show how to use Scikit-learn directly in your browser, through pyodide. This particular example, we will train a simple classifier using the Iris data. Then, we will build an HTML GUI using Iodide, which will be used to interact with the classifier and perform predictions.
## Update your inputs
<div>
Change Sepal length:
<input id="sepalLengthInput" type="range" step=0.1 min=4 max=8><br>
Change Sepal width:
open Printf;;
type attribute =
| Class of string
| Href of string
| Src of string
| Style of string
| Alt of string
| Width of int
| Height of int