Skip to content

Commit

Permalink
replaced pycountry with iso3166
Browse files Browse the repository at this point in the history
  • Loading branch information
aman-17 authored and rlouf committed Feb 12, 2025
1 parent 69418da commit 6c598c3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
23 changes: 15 additions & 8 deletions outlines/types/countries.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
"""Generate valid country codes and names."""
from enum import Enum

import pycountry
from iso3166 import countries

ALPHA_2_CODE = [(country.alpha_2, country.alpha_2) for country in pycountry.countries]

def get_country_flags():
"""Generate Unicode flags for all ISO 3166-1 alpha-2 country codes in Alpha2 Enum."""
base = ord('🇦')
return {code.name: chr(base + ord(code.name[0]) - ord('A')) + chr(base + ord(code.name[1]) - ord('A')) for code in Alpha2}

ALPHA_2_CODE = [(country.alpha2, country.alpha2) for country in countries]
Alpha2 = Enum("Alpha_2", ALPHA_2_CODE) # type:ignore

ALPHA_3_CODE = [(country.alpha_3, country.alpha_3) for country in pycountry.countries]
Alpha3 = Enum("Alpha_2", ALPHA_3_CODE) # type:ignore
ALPHA_3_CODE = [(country.alpha3, country.alpha3) for country in countries]
Alpha3 = Enum("Alpha_3", ALPHA_3_CODE) # type:ignore

NUMERIC_CODE = [(country.numeric, country.numeric) for country in pycountry.countries]
NUMERIC_CODE = [(str(country.numeric), str(country.numeric)) for country in countries]
Numeric = Enum("Numeric_code", NUMERIC_CODE) # type:ignore

NAME = [(country.name, country.name) for country in pycountry.countries]
NAME = [(country.name, country.name) for country in countries]
Name = Enum("Name", NAME) # type:ignore

FLAG = [(country.flag, country.flag) for country in pycountry.countries]
Flag = Enum("Flag", FLAG) # type:ignore
flag_mapping = get_country_flags()
FLAG = [(flag, flag) for code, flag in flag_mapping.items()]
Flag = Enum("Flag", FLAG) # type:ignore
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dependencies = [
"requests",
"tqdm",
"typing_extensions",
"pycountry",
"iso3166",
"airportsdata",
"torch",
"outlines_core==0.1.26",
Expand Down Expand Up @@ -145,7 +145,7 @@ module = [
"vllm.*",
"uvicorn.*",
"fastapi.*",
"pycountry.*",
"iso3166.*",
"airportsdata.*",
"outlines_core.*",
"genson",
Expand Down

0 comments on commit 6c598c3

Please sign in to comment.