Spaces:
Runtime error
Runtime error
first commit
Browse files
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import urllib.request
|
2 |
+
import random
|
3 |
+
import json
|
4 |
+
import gradio
|
5 |
+
|
6 |
+
page = urllib.request.urlopen('https://raw.githubusercontent.com/mazyvan/most-common-spanish-words/master/most-common-spanish-words-v5.txt').read().decode()
|
7 |
+
words = page.split('\n')
|
8 |
+
len(words)
|
9 |
+
|
10 |
+
len_to_words = {}
|
11 |
+
for word in words:
|
12 |
+
if len(word) not in len_to_words:
|
13 |
+
len_to_words[len(word)] = [word]
|
14 |
+
else:
|
15 |
+
len_to_words[len(word)].append(word)
|
16 |
+
|
17 |
+
def get_random_word(n_letters, forbidden_letters='', required_letters=''):
|
18 |
+
random.shuffle(len_to_words[n_letters])
|
19 |
+
for word in len_to_words[n_letters]:
|
20 |
+
lower_word = word.lower()
|
21 |
+
if any(letter in lower_word for letter in forbidden_letters):
|
22 |
+
continue
|
23 |
+
if required_letters:
|
24 |
+
if all(letter in lower_word for letter in required_letters):
|
25 |
+
return '# ' + word
|
26 |
+
else:
|
27 |
+
return '# ' + word
|
28 |
+
|
29 |
+
description = """
|
30 |
+
Genera palabras aleatorias con el número deseado de letras para aprender a leer.
|
31 |
+
Se puede forzar a que las palabras tengan o no tengan determinadas letras
|
32 |
+
"""
|
33 |
+
interface = gradio.Interface(
|
34 |
+
get_random_word,
|
35 |
+
inputs=[gradio.Slider(2, 15, value=5, step=1, label='Número de letras'),
|
36 |
+
gradio.Textbox(label='Letras prohibidas'),
|
37 |
+
gradio.Textbox(label='Letras obligatorias')],
|
38 |
+
#outputs=[gradio.Textbox(label='')],
|
39 |
+
outputs=[gradio.Markdown(label='')],
|
40 |
+
title='Aprende a leer',
|
41 |
+
description=description,
|
42 |
+
allow_flagging=False)
|
43 |
+
interface.launch(server_name="0.0.0.0")
|