Skip to content

Instantly share code, notes, and snippets.

@betterdatascience
betterdatascience / app.py
Created October 28, 2020 06:31
001_fastapi
# 1. Library imports
import uvicorn
from fastapi import FastAPI
# 2. Create the app object
app = FastAPI()
# 3. Index route, opens automatically on http://127.0.0.1:8000
@app.get('/')
def index():
@betterdatascience
betterdatascience / app.py
Created October 28, 2020 06:40
002_fastapi
import uvicorn
from fastapi import FastAPI
app = FastAPI()
@app.get('/')
def index():
'''
This is a first docstring.
'''
@betterdatascience
betterdatascience / app.py
Created October 28, 2020 06:43
004_fastapi
# 1. Library imports
import uvicorn
from fastapi import FastAPI
from Model import IrisModel, IrisSpecies
# 2. Create app and model objects
app = FastAPI()
model = IrisModel()
# 3. Expose the prediction functionality, make a prediction from the passed
@betterdatascience
betterdatascience / test.py
Created October 28, 2020 06:45
005_fastapi
import requests
new_measurement = {
'sepal_length': 5.7,
'sepal_width': 3.1,
'petal_length': 4.9,
'petal_width': 2.2
}
response = requests.post('http://127.0.0.1:8000/predict', json=new_measurement)
@betterdatascience
betterdatascience / app.R
Created October 30, 2020 10:51
001_powerbi_shiny
library(gapminder)
library(ggplot2)
library(dplyr)
library(shiny)
ui <- fluidPage(
titlePanel("Gapminder explorer", windowTitle = NULL),
plotOutput("line")
)
@betterdatascience
betterdatascience / app.R
Created October 30, 2020 10:53
002_powerbi_shiny
library(shiny)
library(gapminder)
library(dplyr)
library(ggplot2)
ui <- fluidPage(
titlePanel("Gapminder explorer", windowTitle = NULL),
sidebarPanel(
width = 3,
tags$h4("Filter"),
@betterdatascience
betterdatascience / app.py
Created October 30, 2020 20:45
002_emails
msg = EmailMessage()
msg['Subject'] = 'This is my first Python email'
msg['From'] = EMAIL_ADDRESS
msg['To'] = EMAIL_ADDRESS
msg.set_content('And it actually works')
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
smtp.login(EMAIL_ADDRESS, EMAIL_PASSWORD)
smtp.send_message(msg)
@betterdatascience
betterdatascience / app.py
Created October 30, 2020 20:46
003_emails
msg = EmailMessage()
msg['Subject'] = 'This is my email for multiple people'
msg['From'] = EMAIL_ADDRESS
msg['To'] = ['recipient1@gmail.com', 'recipient2@gmail.com']
msg.set_content('It works!')
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
smtp.login(EMAIL_ADDRESS, EMAIL_PASSWORD)
smtp.send_message(msg)
@betterdatascience
betterdatascience / app.py
Created October 30, 2020 20:47
004_emails
msg = EmailMessage()
msg['Subject'] = 'This is my email with PDF attachment'
msg['From'] = EMAIL_ADDRESS
msg['To'] = EMAIL_ADDRESS
msg.set_content('See below')
with open('ExampleDoc.pdf', 'rb') as pdf:
msg.add_attachment(pdf.read(), maintype='application', subtype='octet-stream', filename=pdf.name)
@betterdatascience
betterdatascience / missforest.py
Created November 4, 2020 11:32
001_missforest
import numpy as np
import pandas as pd
iris = pd.read_csv('iris.csv')
# Keep an untouched copy for later
iris_orig = iris.copy()
iris.head()