Skip to content

Commit

Permalink
Finished training custom models. Still needs more training as model i…
Browse files Browse the repository at this point in the history
…s currently lowkey racist
  • Loading branch information
liunick committed Aug 16, 2017
1 parent 8a66cca commit bd98a42
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
12 changes: 9 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
app.config['DEBUG'] = True
app.config['UPLOAD_FOLDER'] = 'uploads'
app.config['FILE_EXTENSIONS'] = ['png', 'jpg', 'pdf', 'jpeg', 'gif']
app.config['KEYWORDS'] = ['pasta', 'spaghetti', 'angel-hair pasta']
app.config['KEYWORDS_PASTA'] = ['pasta', 'spaghetti', 'angel-hair pasta']
app.config['KEYWORDS'] = ['Neil']
app.config['APPROVAL_PERCENTAGE'] = .6000

def allowed_file(filename):
Expand All @@ -22,6 +23,11 @@ def is_pasta(data):
return any(x in data.keys() for x in app.config['KEYWORDS']) \
and any(i > cutoff for i in (data[x] for x in app.config['KEYWORDS']))

def is_significant(data):
cutoff = app.config['APPROVAL_PERCENTAGE']
return any(x in data.keys() for x in app.config['KEYWORDS']) \
and any(i > cutoff for i in (data[x] for x in app.config['KEYWORDS']))

def clarifai_data(model, filename):
model = clarifaiApp.models.get(model)
output = model.predict_by_filename(filename=filename)
Expand All @@ -42,8 +48,8 @@ def uploadFile():
safeFile = secure_filename(fileObj.filename)
local_filename = os.path.join(app.config['UPLOAD_FOLDER'], safeFile)
fileObj.save(local_filename)
data = clarifai_data('food-items-v1.0', local_filename)
return render_template('index.html', data=is_pasta(data))
data = clarifai_data('Friends', local_filename)
return render_template('index.html', data=is_significant(data), imgSrc=local_filename)

@app.route('/uploads/<filename>')
def uploaded_file(filename):
Expand Down
6 changes: 3 additions & 3 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ <h3 class="text-muted">How To Upload a File</h3>
<input type="file" name="file"><br /><br />
<input type="submit" value="Upload">
</form>

<img style="height:480px;max-width:500px;width:" src={{imgSrc}} />
{% if data==True %}
It is Pasta
It is Neil!!
{% else %}
It is not Pasta
It is not Neil :(
{% endif %}
</div>
</div>
Expand Down
17 changes: 11 additions & 6 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,17 @@ def showAllModels():

#list of all
urls = [
'https://images.eatthismuch.com/site_media/img/4440_laurabedo_38887c39-cc1c-430d-bd4d-2562c09df8cc.png',
'http://img-aws.ehowcdn.com/350x235p/photos.demandstudios.com/198/37/fotolia_8334344_XS.jpg',
'http://s.eatthis-cdn.com/media/images/ext/846505625/rice-cakes.jpg',

'https://scontent.fdet1-1.fna.fbcdn.net/v/t1.0-9/16640621_1407871549237242_8731785688204173502_n.jpg?oh=5525a02bd34ac7f65d6bb0a54ac4e4f4&oe=59F033FA',
'https://scontent.fdet1-1.fna.fbcdn.net/v/t1.0-9/14708219_1233740213334125_731178637874495198_n.jpg?oh=52105b2e075589444e0c6cfca755d975&oe=59EFCEB2',
'https://scontent.fdet1-1.fna.fbcdn.net/v/t1.0-9/14291921_1252052744819124_8336105302969309541_n.jpg?oh=459016e414efc7806f3bf0fa13383688&oe=5A306660',
'https://scontent.fdet1-1.fna.fbcdn.net/v/t1.0-9/14141903_1236184579739274_7991324806780006796_n.jpg?oh=1780f0e08ca0dd27d84c7ee297a6018e&oe=5A1D73E2',
'https://scontent.fdet1-1.fna.fbcdn.net/v/t1.0-9/14051795_1236184316405967_2865724824847652055_n.jpg?oh=3873b418d711a461c92d9aaf85bfb6a4&oe=5A2A87EF',
'https://scontent.fdet1-1.fna.fbcdn.net/v/t1.0-9/13886902_1817843611783778_1673974955086866955_n.jpg?oh=fecc4646295949d404e935b25e40e9a1&oe=5A2D8460',
'https://scontent.fdet1-1.fna.fbcdn.net/v/t1.0-1/17201271_10210800547482891_3681294658914218944_n.jpg?oh=78e33837e1e26035e699ec0c5f8ee29e&oe=5A32CBF5',
'https://scontent.fdet1-1.fna.fbcdn.net/v/t1.0-9/16729009_10210573665530984_7145416717855968866_n.jpg?oh=b407f448138211fbdcc6ac7e25f864df&oe=5A1D7F86',
'https://scontent.fdet1-1.fna.fbcdn.net/v/t1.0-9/20729639_10212344408958463_6202965616116237856_n.jpg?oh=069a8070fac76c9a04d27192506f4cfb&oe=5A336D1E',
'https://scontent.fdet1-1.fna.fbcdn.net/v/t1.0-9/14184459_10209001400505341_4583114924133526486_n.jpg?oh=936b6e0dc37033968630bb3831e53b73&oe=5A1F79F1',
]
concepts = ['Neil']
modelName = 'Friends'
trainModel(urls, concepts, modelName)
showAllModels()
trainModel(urls, concepts, modelName)

0 comments on commit bd98a42

Please sign in to comment.