<commit_before>from ingredients import get_ingredients
from barcodes import get_country
from origins import origins_us_list
import web


urls = (
  '/', 'BarcodeServer'
)

render = web.template.render('static/')

def main(barcode, num_countries=10):
    country = get_country(barcode)
    r = get_ingredients(barcode)
    if country == 'USA':
        origins = origins_us_list(r['ingredients'])
        if len(origins) > 0:
            origins.sort(ascending=False)
            origins = origins.iloc[:num_countries]
            origins = (origins/origins.sum()).to_dict()
    else:
        origins = {}
    return r['product_name'], origins


app = web.application(urls, globals())

class BarcodeServer:
    def GET(self):
        return render.form()

    def POST(self):
        form = web.input(barcode="")
        product, origins = main(form.barcode)
        return render.index(origins=origins, product=product)

if __name__ == "__main__":
    app.run()<commit_msg>set VCAP_APP_PORT<commit_after>from ingredients import get_ingredients
from barcodes import get_country
from origins import origins_us_list
import web
import os


urls = (
  '/', 'BarcodeServer'
)

render = web.template.render('static/')

PORT = int(os.getenv('VCAP_APP_PORT', 8000))


def main(barcode, num_countries=10):
    country = get_country(barcode)
    r = get_ingredients(barcode)
    if country == 'USA':
        origins = origins_us_list(r['ingredients'])
        if len(origins) > 0:
            origins.sort(ascending=False)
            origins = origins.iloc[:num_countries]
            origins = (origins/origins.sum()).to_dict()
    else:
        origins = {}
    return r['product_name'], origins


app = web.application(urls, globals())

class BarcodeServer:
    def GET(self):
        return render.form()

    def POST(self):
        form = web.input(barcode="")
        product, origins = main(form.barcode)
        return render.index(origins=origins, product=product)

if __name__ == "__main__":
    app.run(port=PORT)
{'fraction_non_alphanumeric': 0.1221449851042701, 'fraction_numerical': 0.004965243296921549, 'mean_word_length': 3.2243186582809225, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '24827', 'n_tokens_mistral': 651, 'n_tokens_neox': 647, 'n_words': 137}