File size: 1,706 Bytes
c70cfd4
 
 
 
 
3fe75b8
94348fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f3bf74c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94348fd
c70cfd4
 
5c12cf0
aa80aa2
f3bf74c
d194f54
ac6f4b7
f3bf74c
5c12cf0
0497aff
d1d5799
 
3fe75b8
f3bf74c
0497aff
 
c70cfd4
 
 
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
import gradio as gr
import difflib,time,numpy
# Dictionary
dictionaryFile=open('words.txt','r') # Open words file
dictionary=dictionaryFile.readlines() # Read words file into list
dictionaryFile.close()

def check3(inp, inp2):
    if len(inp) > len(inp2):
        longest = inp
        shortest = inp2
    else:
        shortest = inp
        longest = inp2
    ls = len(shortest)
    ll = len(longest)
    out = 0
    for i in range(ls):
        if shortest[i] in longest:
            out += 1
        if shortest[i] == longest[i]:
            out += 2
    return out - ((out-ls)*0.5) - (ll-ls) * 0.5

class Neuron:
    def __init__(self, inp, output: str):
        self.output = output
        self.inp = inp
    def train(self, inpr):
        cid = random.randint(0, len(inpr)-1)
        c2id = random.randint(0, len(inpr[cid])-1)
        if inpr[cid][c2id] not in self.inp:
            self.inp.append(inpr[cid][c2id])
        cid = random.randint(0, len(self.inp)-1)
        if not check(self.inp[cid], inpr):
            del self.inp[cid]

def check(word, list2d):
    for i in list2d:
        if word in i: return True
    
# Work
def get_matches(text):
    # prepare text
    textR=str(text)
    textR=textR.split() # Split inputed text to list
    # Variables
    queue=len(textR)
    output=[]
    # try to correct it
    try:
        ##return(difflib.get_close_matches(text, dictionary))  #[0].replace("\n", "")
        for x in range(queue):
            output.append(difflib.get_close_matches(textR[x], dictionary))
        return(output)
    except Exception as ex: # Print error if error
        return(ex)

iface = gr.Interface(fn=get_matches, inputs="text", outputs="text")
iface.launch()