Skip to content

Instantly share code, notes, and snippets.

@malev
Created July 28, 2014 04:20
Show Gist options
  • Save malev/5c6ae7230ca01778760a to your computer and use it in GitHub Desktop.
Save malev/5c6ae7230ca01778760a to your computer and use it in GitHub Desktop.
Gender detector API version
import json
from gender_detector import GenderDetector
from bottle import route, run, response
detector_ar = GenderDetector('ar')
detector_uk = GenderDetector('uk')
detector_us = GenderDetector('us')
@route('/<country>/<name>')
def index(country, name):
gender = 'unknown'
if country == 'ar':
gender = detector_ar.guess(name)
elif country == 'us':
gender = detector_us.guess(name)
elif country == 'uk':
gender = detector_uk.guess(name)
output = json.dumps({'name': name, 'gender': gender, 'country': country })
response.content_type = 'application/json'
return output
run(host='localhost', port=8080)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment