File size: 2,142 Bytes
46686f8
 
 
 
 
0f7d64d
 
 
 
 
 
 
 
 
e37d1d1
0f7d64d
 
46686f8
e37d1d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46686f8
0f7d64d
 
46686f8
0f7d64d
46686f8
 
0f7d64d
46686f8
 
 
 
0f7d64d
 
46686f8
 
 
 
 
 
 
 
 
 
 
 
 
 
0f7d64d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import urllib.request
import random
import gradio


def download_data():
    page = urllib.request.urlopen('https://raw.githubusercontent.com/mazyvan/most-common-spanish-words/master/most-common-spanish-words-v5.txt').read().decode()
    words = page.split('\n')
    len_to_words = {}
    for word in words:
        if len(word) not in len_to_words:
            len_to_words[len(word)] = [word]
        else:
            len_to_words[len(word)].append(word)
    len_to_words[2] = get_syllabes()
    return len_to_words


def get_syllabes():
    syllabes = set()
    vowels = 'aeiou'
    consonants = 'bcdfghjklmnpqrstvwxyz'
    for consonant in consonants:
        for vowel in vowels:
            if consonant in 'gq' and vowel in 'ei':
                syllabes.add(consonant + 'u' + vowel)
            else:
                syllabes.add(consonant + vowel)
    remove = ['qu', 'qa', 'qi', 'qo', 'qu']
    syllabes = sorted(list(syllabes.difference(remove)))
    print(syllabes)
    return syllabes


def get_random_word(n_letters, forbidden_letters='', required_letters=''):
    random.shuffle(LEN_TO_WORDS[n_letters])
    for word in LEN_TO_WORDS[n_letters]:
        lower_word = word.lower()
        if any(letter in lower_word for letter in forbidden_letters.lower()):
            continue
        if required_letters:
            if all(letter in lower_word for letter in required_letters.lower()):
                return '# ' + word
        else:
            return '# ' + word


LEN_TO_WORDS = download_data()
description = """
Genera palabras aleatorias con el número deseado de letras para aprender a leer.
Se puede forzar a que las palabras tengan o no tengan determinadas letras
"""
interface = gradio.Interface(
    get_random_word,
    inputs=[gradio.Slider(2, 15, value=5, step=1, label='Número de letras'),
            gradio.Textbox(label='Letras prohibidas'),
            gradio.Textbox(label='Letras obligatorias')],
    #outputs=[gradio.Textbox(label='')],
    outputs=[gradio.Markdown(label='')],
    title='Aprende a leer',
    description=description,
    allow_flagging=False)
interface.launch(server_name="0.0.0.0")