Skip to content

Instantly share code, notes, and snippets.

View everling-prime's full-sized avatar
💯

Skip Everling everling-prime

💯
View GitHub Profile
@everling-prime
everling-prime / clarifai_tagger.py
Created October 25, 2018 08:32
This function takes an image (URL) and returns a string list of tags predicted by Clarifai
from clarifai.rest import ClarifaiApp
app = ClarifaiApp()
def get_concept_tags(image_url):
response_data = app.tag_urls([image_url])
tags = []
for concept in response_data['outputs'][0]['data']['concepts']:
tags.append(concept['name'])
@everling-prime
everling-prime / app.py
Last active October 25, 2018 08:38
Scarefai Flask App -- Clarifai + Twilio
from flask import Flask, request
from twilio.twiml.messaging_response import MessagingResponse
from clarifai_tagger import get_concept_tags
app = Flask(__name__)
#this is a list of concepts we will look for among all possible Clarifai concepts
spooky_concepts = ['scary','eerie','dark','monochrome','spider','spiderweb',
'arachnid','phobia','fog','mystery','shadow','abandoned',
@everling-prime
everling-prime / display_image_jupyter
Created August 25, 2018 01:18
Display an image in a Jupyter Notebook from URL
from IPython.display import Image
from IPython.core.display import HTML
Image(url="")
@everling-prime
everling-prime / prepare_for_fasttext.py
Created June 25, 2018 09:13
Label tweets for fasttext
def prepare_for_fasttext(tweets_df):
with open('tweets.txt', 'w') as file:
for i, row in tweets_df.iterrows():
if row['class'] == 0:
label = ' __label__ hate_speech'
if row['class'] == 1:
label = ' __label__ offensive_language'
else:
label = ' __label__ neither'
@everling-prime
everling-prime / memoize_wrapper.py
Last active November 27, 2017 18:19
Decorate Python functions with memo to allow for efficient caching of intermediate results (memoization)
def memo(f):
"Memoize function f, whose args must all be hashable."
cache = {}
def fmemo(*args):
if args not in cache:
cache[args] = f(*args)
return cache[args]
fmemo.cache = cache
return fmemo
@everling-prime
everling-prime / nerdy.ipynb
Created September 29, 2017 07:51
Nerdy Notebook (Machine Learning with NPAS)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.