[Python] Google Cloud Translate: num_valid_languages_in_csv = 1

Discussão em 'Python' iniciado por Stack, Março 17, 2025.

  1. Stack

    Stack Membro Participativo

    Attempting to add a glossary to Google Cloud Translate, but am receiving the following error:

    Traceback (most recent call last):
    File "Python_SetGlossary.py", line 36, in <module>
    result = operation.result(timeout=90)
    File "C:\Programming Installs\Python\lib\site-packages\google\api_core\future\polling.py", line 127, in result
    raise self._exception
    google.api_core.exceptions.GoogleAPICallError: None Failed to parse content of input file. Error: Not enough valid languages in CSV file. Must have terms for at least two different languages. num_valid_languages_in_csv = 1


    The CSV file (below) was created using the example provided by Google for equivalent terms sets.

    en,fr,pos
    Canadian Meteorological Service of Environment Canada,Service météorologique d'Environnement Canada,noun
    Jacques Cartier Strait,détroit de Jacques-Cartier,noun
    the St. Lawrence Global Observatory,l'Observatoire global du Saint-Laurent,noun
    St. Lawrence Global Observatory,Observatoire global du Saint-Laurent,noun


    This was uploaded to Google Cloud Storage. I then attempted to create an online glossary by making at available to the Cloud Translation API, again via the code provided by Google for equivalent terms sets.

    from google.cloud import translate_v3 as translate

    # def sample_create_glossary(project_id, input_uri, glossary_id):

    """Create Glossary"""
    client = translate.TranslationServiceClient()

    # TODO(developer): Uncomment and set the following variables
    project_id = 'testtranslate'
    glossary_id = 'glossary-en-fr-bidirectional'
    input_uri = 'gs://bidirectional-en-fr/bidirectional-glossary.csv'
    location = 'us-central1' # The location of the glossary

    name = client.glossary_path(
    project_id,
    location,
    glossary_id)
    language_codes_set = translate.types.Glossary.LanguageCodesSet(
    language_codes=['en', 'fr'])

    gcs_source = translate.types.GcsSource(
    input_uri=input_uri)

    input_config = translate.types.GlossaryInputConfig(
    gcs_source=gcs_source)

    glossary = translate.types.Glossary(
    name=name,
    language_codes_set=language_codes_set,
    input_config=input_config)

    parent = client.location_path(project_id, location)

    operation = client.create_glossary(parent=parent, glossary=glossary)

    result = operation.result(timeout=90)
    print('Created: {}'.format(result.name))
    print('Input Uri: {}'.format(result.input_config.gcs_source.input_uri))


    Can anybody help me figure out what is going on / what I'm doing wrong? (Or what Google is doing wrong. Some of their documentation is definitely suspect. But also I am not particularly experienced with Python and could easily be missing something.)

    Continue reading...

Compartilhe esta Página