Spaces:
Build error
Build error
Commit
·
7cfa475
1
Parent(s):
57dbcfd
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
iimport gradio as gr
|
2 |
+
|
3 |
+
def convert_to_french_letters(number):
|
4 |
+
# Define lists of French words for numbers
|
5 |
+
units = ['', 'un', 'deux', 'trois', 'quatre', 'cinq', 'six', 'sept', 'huit', 'neuf']
|
6 |
+
tens = ['', 'dix', 'vingt', 'trente', 'quarante', 'cinquante', 'soixante', 'soixante-dix', 'quatre-vingt', 'quatre-vingt-dix']
|
7 |
+
# Define special cases for 70, 80, and 90
|
8 |
+
special_tens = {70: 'soixante-dix', 80: 'quatre-vingt', 90: 'quatre-vingt-dix'}
|
9 |
+
|
10 |
+
# Handle special cases
|
11 |
+
if number in special_tens:
|
12 |
+
return special_tens[number]
|
13 |
+
|
14 |
+
# Extract digits from number
|
15 |
+
billions = number // 1000000000
|
16 |
+
millions = (number // 1000000) % 1000
|
17 |
+
thousands = (number // 1000) % 1000
|
18 |
+
hundreds = (number // 100) % 10
|
19 |
+
tens_and_units = number % 100
|
20 |
+
|
21 |
+
# Convert digits to words
|
22 |
+
words = []
|
23 |
+
if billions > 0:
|
24 |
+
if billions == 1:
|
25 |
+
words.append('un milliard')
|
26 |
+
else:
|
27 |
+
words.append(convert_to_french_letters(billions) + ' milliards')
|
28 |
+
if millions > 0:
|
29 |
+
if millions == 1:
|
30 |
+
words.append('un million')
|
31 |
+
else:
|
32 |
+
words.append(convert_to_french_letters(millions) + ' millions')
|
33 |
+
if thousands > 0:
|
34 |
+
if thousands == 1:
|
35 |
+
words.append('mille')
|
36 |
+
else:
|
37 |
+
words.append(convert_to_french_letters(thousands) + ' mille')
|
38 |
+
if hundreds > 0:
|
39 |
+
if hundreds == 1:
|
40 |
+
words.append('cent')
|
41 |
+
else:
|
42 |
+
words.append(units[hundreds] + ' cent')
|
43 |
+
if tens_and_units > 0:
|
44 |
+
if tens_and_units < 10:
|
45 |
+
words.append(units[tens_and_units])
|
46 |
+
elif tens_and_units < 20:
|
47 |
+
words.append('dix-' + units[tens_and_units-10])
|
48 |
+
else:
|
49 |
+
tens_digit = tens[tens_and_units // 10]
|
50 |
+
units_digit = units[tens_and_units % 10]
|
51 |
+
if tens_digit == 'vingt' and units_digit == 'un':
|
52 |
+
tens_digit = 'vingt-et-un'
|
53 |
+
units_digit = ''
|
54 |
+
words.append(tens_digit + '-' + units_digit)
|
55 |
+
|
56 |
+
# Join words and return result
|
57 |
+
return ' '.join(words)
|
58 |
+
|
59 |
+
inputs = gr.inputs.Number(label="Number to convert")
|
60 |
+
outputs = gr.outputs.Textbox(label="Result")
|
61 |
+
|
62 |
+
title = "Number to French Letters Converter"
|
63 |
+
description = "A program that converts numbers to their French letter equivalents"
|
64 |
+
examples = [[25230], [1000000000], [1234567890]]
|
65 |
+
|
66 |
+
iface = gr.Interface(fn=convert_to_french_letters, inputs=inputs, outputs=outputs, title=title, description=description, examples=examples)
|
67 |
+
|
68 |
+
iface.launch()
|