Spaces:
Build error
Build error
| import gradio as gr | |
| def convert_to_french_letters(number): | |
| # Define lists of French words for numbers | |
| units = ['', 'un', 'deux', 'trois', 'quatre', 'cinq', 'six', 'sept', 'huit', 'neuf'] | |
| tens = ['', 'dix', 'vingt', 'trente', 'quarante', 'cinquante', 'soixante', 'soixante-dix', 'quatre-vingt', 'quatre-vingt-dix'] | |
| # Define special cases for 70, 80, and 90 | |
| special_tens = {70: 'soixante-dix', 80: 'quatre-vingt', 90: 'quatre-vingt-dix'} | |
| # Handle special cases | |
| if number in special_tens: | |
| return special_tens[number] | |
| # Extract digits from number | |
| billions = number // 1000000000 | |
| millions = (number // 1000000) % 1000 | |
| thousands = (number // 1000) % 1000 | |
| hundreds = (number // 100) % 10 | |
| tens_and_units = number % 100 | |
| # Convert digits to words | |
| words = [] | |
| if billions > 0: | |
| if billions == 1: | |
| words.append('un milliard') | |
| else: | |
| words.append(convert_to_french_letters(billions) + ' milliards') | |
| if millions > 0: | |
| if millions == 1: | |
| words.append('un million') | |
| else: | |
| words.append(convert_to_french_letters(millions) + ' millions') | |
| if thousands > 0: | |
| if thousands == 1: | |
| words.append('mille') | |
| else: | |
| words.append(convert_to_french_letters(thousands) + ' mille') | |
| if hundreds > 0: | |
| if hundreds == 1: | |
| words.append('cent') | |
| else: | |
| words.append(units[int(hundreds)] + ' cent') | |
| if tens_and_units > 0: | |
| if tens_and_units < 10: | |
| words.append(units[int(tens_and_units)]) | |
| elif tens_and_units < 20: | |
| words.append('dix-' + units[int(tens_and_units-10)]) | |
| else: | |
| tens_digit = tens[int(tens_and_units / 10)] | |
| units_digit = units[int(tens_and_units % 10)] | |
| if tens_digit == 'vingt' and units_digit == 'un': | |
| tens_digit = 'vingt-et-un' | |
| units_digit = '' | |
| words.append(tens_digit + '-' + units_digit) | |
| # Join words and return result | |
| return ' '.join(words) | |
| inputs = gr.inputs.Number(label="Number to convert") | |
| outputs = gr.outputs.Textbox(label="Result") | |
| title = "Number to French Letters Converter" | |
| description = "A program that converts numbers to their French letter equivalents" | |
| examples = [[25230], [1000000000], [1234567890]] | |
| iface = gr.Interface(fn=convert_to_french_letters, inputs=inputs, outputs=outputs, title=title, description=description, examples=examples) | |
| iface.launch() |