This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from torch.autograd import Variable | |
| import librosa | |
| import numpy as np | |
| import torch | |
| N_FFT=2048 | |
| def read_audio_spectum(filename): | |
| x, fs = librosa.load(filename) | |
| S = librosa.stft(x, N_FFT) | |
| p = np.angle(S) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # adapted from: https://github.com/alishdipani/Neural-Style-Transfer-Audio/blob/master/NeuralStyleTransfer.py | |
| import torch | |
| import torch.nn as nn | |
| class GramMatrix(nn.Module): | |
| def forward(self, input): | |
| a, b, c = input.size() # a=batch size(=1) | |
| # b=number of feature maps |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import torch | |
| import torch.nn as nn | |
| # adapted from: https://ghamrouni.github.io/stn-tuto/advanced/neural_style_tutorial.html# | |
| class ContentLoss(nn.Module): | |
| def __init__(self, target, weight): | |
| super(ContentLoss, self).__init__() | |
| # we 'detach' the target content from the tree used | |
| self.target = target.detach() * weight |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| # download youtube url using ffmpeg | |
| # adapted from: https://github.com/ytdl-org/youtube-dl/issues/622#issuecomment-162337869 | |
| def download_from_url_ffmpeg(url, output, minute_mark = 1): | |
| try: | |
| os.remove(output) | |
| except: | |
| pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from ObjectDetector import Detector | |
| import io | |
| from flask import Flask, render_template, request, send_from_directory, send_file | |
| from PIL import Image | |
| import requests | |
| import os | |
| import img_transforms | |
| app = Flask(__name__) | |
| detector = Detector() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import PIL | |
| from PIL import Image | |
| # adapted from: https://github.com/jantic/DeOldify/blob/master/deoldify/filters.py | |
| def _scale_to_square(orig, targ): | |
| targ_sz = (targ, targ) | |
| return orig.resize(targ_sz, resample=PIL.Image.BILINEAR) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # adapted from: https://github.com/npatta01/web-deep-learning-classifier/blob/master/docs/2_b_gcloud.md | |
| GCP_PROJECT=fresh-runway-246001 | |
| APP_NAME=neelsmlapp | |
| REGION="us-central1" | |
| MEMORY=2G | |
| # set project to correct one | |
| gcloud config set project $GCP_PROJECT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from Detector import Detector | |
| import io | |
| from flask import Flask, render_template, request, send_from_directory, send_file | |
| from PIL import Image | |
| import requests | |
| import os | |
| import img_transforms | |
| app = Flask(__name__) | |
| detector = Detector() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import io | |
| from flask import Flask, render_template, request, send_from_directory, send_file | |
| from PIL import Image | |
| import requests | |
| import os | |
| # function to load img from url | |
| def load_image_url(url): | |
| response = requests.get(url) | |
| img = Image.open(io.BytesIO(response.content)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import io | |
| from flask import Flask, render_template, request, send_from_directory, send_file | |
| from PIL import Image | |
| import requests | |
| import os | |
| import urllib.request | |
| app = Flask(__name__) | |
| @app.route("/") |