Created
July 28, 2014 04:20
-
-
Save malev/5c6ae7230ca01778760a to your computer and use it in GitHub Desktop.
Gender detector API version
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 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