Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# %%
|
2 |
+
import inspect
|
3 |
+
import random
|
4 |
+
|
5 |
+
import gradio as gr
|
6 |
+
import pandas as pd
|
7 |
+
|
8 |
+
url = "https://raw.githubusercontent.com/dwyl/english-words/master/words.txt"
|
9 |
+
df = pd.read_table(url, header=None)
|
10 |
+
words = df[0].astype(str).tolist()
|
11 |
+
words = [x.lower() for x in words if len(x) == 5 and x.isalpha()]
|
12 |
+
|
13 |
+
|
14 |
+
def filter_one_word(
|
15 |
+
w,
|
16 |
+
no="",
|
17 |
+
yes="",
|
18 |
+
no1="",
|
19 |
+
no2="",
|
20 |
+
no3="",
|
21 |
+
no4="",
|
22 |
+
no5="",
|
23 |
+
yes1="",
|
24 |
+
yes2="",
|
25 |
+
yes3="",
|
26 |
+
yes4="",
|
27 |
+
yes5="",
|
28 |
+
):
|
29 |
+
for c in w:
|
30 |
+
if c in no:
|
31 |
+
return False
|
32 |
+
for c in yes:
|
33 |
+
if c not in w:
|
34 |
+
return False
|
35 |
+
nos = [no1, no2, no3, no4, no5]
|
36 |
+
for c, n in zip(w, nos):
|
37 |
+
if c in n:
|
38 |
+
return False
|
39 |
+
yeses = [yes1, yes2, yes3, yes4, yes5]
|
40 |
+
for c, n in zip(w, yeses):
|
41 |
+
if n and c != n:
|
42 |
+
return False
|
43 |
+
return True
|
44 |
+
|
45 |
+
|
46 |
+
def process_args(chars):
|
47 |
+
cs = set([c for c in chars.lower() if c.isalpha()])
|
48 |
+
return "".join(list(cs))
|
49 |
+
|
50 |
+
|
51 |
+
def main(
|
52 |
+
no="",
|
53 |
+
yes="",
|
54 |
+
no1="",
|
55 |
+
no2="",
|
56 |
+
no3="",
|
57 |
+
no4="",
|
58 |
+
no5="",
|
59 |
+
yes1="",
|
60 |
+
yes2="",
|
61 |
+
yes3="",
|
62 |
+
yes4="",
|
63 |
+
yes5="",
|
64 |
+
):
|
65 |
+
no, yes, no1, no2, no3, no4, no5, yes1, yes2, yes3, yes4, yes5 = map(
|
66 |
+
process_args, [no, yes, no1, no2, no3, no4, no5, yes1, yes2, yes3, yes4, yes5]
|
67 |
+
)
|
68 |
+
candidates = [
|
69 |
+
w
|
70 |
+
for w in words
|
71 |
+
if filter_one_word(
|
72 |
+
w, no, yes, no1, no2, no3, no4, no5, yes1, yes2, yes3, yes4, yes5
|
73 |
+
)
|
74 |
+
]
|
75 |
+
return str(len(candidates)), "\n".join(
|
76 |
+
random.sample(candidates, (min(10, len(candidates))))
|
77 |
+
)
|
78 |
+
|
79 |
+
|
80 |
+
args = inspect.getfullargspec(main)
|
81 |
+
iface = gr.Interface(
|
82 |
+
fn=main,
|
83 |
+
inputs=[gr.inputs.Textbox(label=n) for n in args.args],
|
84 |
+
outputs=["text", "text"],
|
85 |
+
).launch()
|