Skip to content

Instantly share code, notes, and snippets.

@MattKovtun
MattKovtun / hash.py
Created October 31, 2018 14:07
Function for calculatin hash
import hashlib, sys, os
def calculate_hash(args):
BUF_SIZE = 65536
file_name = args[0]
if not os.path.isfile(file_name):
return "Not a file"
sha1 = hashlib.sha1()
let model;
const modelURL = 'http://localhost:5000/model';
const preview = document.getElementById("preview");
const predictButton = document.getElementById("predict");
const clearButton = document.getElementById("clear");
const numberOfFiles = document.getElementById("number-of-files");
const fileInput = document.getElementById('file');
let model;
const modelURL = 'http://localhost:5000/model';
const preview = document.getElementById("preview");
const predictButton = document.getElementById("predict");
const clearButton = document.getElementById("clear");
const numberOfFiles = document.getElementById("number-of-files");
const fileInput = document.getElementById('file');
<body>
<h1>TensorflowJS client side prediction</h1>
<h2>When you first time press predict it will take more time, for model to load</h2>
<main>
<input type="file" id="file" multiple>
<label for="file">Choose files</label>
<button type="submit">Predict</button>
<button type="submit">Clear</button>
<span></span>
</main>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>TF JS example</title>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.11.7"></script>
</head>
<body>
</body>
</html>
from flask_cors import CORS
from flask import Flask, request, render_template, json, jsonify, send_from_directory
import json
import cv2
import numpy as np
import io
app = Flask(__name__)
CORS(app)
let model;
const modelURL = 'http://localhost:5000/model';
const preview = document.getElementById("preview");
const predictButton = document.getElementById("predict");
const clearButton = document.getElementById("clear");
const numberOfFiles = document.getElementById("number-of-files");
const fileInput = document.getElementById('file');
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>TF JS example</title>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.11.7"></script>
<link rel="stylesheet" href="../static/frontend/styles.css">
</head>
<body>
<h1 class="title">TensorflowJS client side prediction</h1>
from flask_cors import CORS
from flask import Flask, render_template
app = Flask(__name__)
CORS(app)
@app.route("/", methods=["GET"])
def main():
return render_template('index.html')
# Your training happens here
# Hundreds and hundreds of layers
# Stacked to create the greatest model ever
# don't forget saving to json format
import tensorflowjs as tfjs
tfjs.converters.save_keras_model(model, "model_js")