Skip to content

Instantly share code, notes, and snippets.

View ModMaamari's full-sized avatar

Mohammed A. AL-Maamari ModMaamari

View GitHub Profile
def from_label_studio_to_dataframe( LABEL_STUDIO_URL="",
API_KEY=""):
'''
Goals:
- Load the labeled data from Label Studio
(or from a raw_data dictionary saved locally as a pickle file), clean it, and save it into a panda data frame
Attributes:
- LABEL_STUDIO_URL (url as string): the url for the label studio project you want to get your data from
- API_KEY (string): your Label Studio API_KEY
Returns:
# Import the flask app from __init__.py
from digitReader import app
if __name__ == '__main__':
# Running the app
app.run(debug=True)
# Flask
from flask import render_template, request, jsonify
from digitReader import app
# Utils
import base64
from io import BytesIO
# Image Processing
import cv2
@ModMaamari
ModMaamari / __init__.py
Last active July 7, 2021 14:33
Initialize Flask App
# Import Flask
from flask import Flask
# Iniiate the flask app
app = Flask(__name__)
app.config['SECRET_KEY'] = 'Here you put a secret key as a string'
# Call the routes code
from digitReader import routes
@ModMaamari
ModMaamari / Example front-end interface.html
Last active July 6, 2021 19:20
Example front-end interface
<!DOCTYPE html>
<html>
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
@ModMaamari
ModMaamari / load_trained_models.py
Created July 12, 2020 21:15
Loading Trained Models
from keras.models import load_model
model_name_ = "Model's Name"
model = load_model(f'{PATH}/{model_name_}')
# EX : say you have the model in a folder called "models" and model's name is "myModel.model"
model_name_ = "myModel.model"
model = load_model(f'models/{model_name_}')
agent.tensorboard.step = episode
# Use this line to update the log file:
agent.tensorboard.update_stats(reward_avg=average_reward, reward_min=min_reward, reward_max=max_reward, epsilon=epsilon)
# Fit on all samples as one batch, log only on terminal state
self.model.fit(x = np.array(X).reshape(-1, *env.ENVIRONMENT_SHAPE),
y = np.array(y),
batch_size = MINIBATCH_SIZE, verbose = 0,
shuffle=False, callbacks=[self.tensorboard] if terminal_state else None)
# Custom tensorboard object
self.tensorboard = ModifiedTensorBoard(name, log_dir="{}logs/{}-{}".format(PATH, name, int(time.time())))