File size: 1,295 Bytes
c70cfd4
 
 
 
 
 
94348fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c70cfd4
 
5c12cf0
aa80aa2
d194f54
 
d1d5799
ac6f4b7
900104b
5c12cf0
0497aff
d1d5799
 
b337856
d1d5799
 
900104b
 
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
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


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
    
# Work
def get_matches(text):
    # prepare text
    textR=str(text)
    textR=textR.split() # Some shitty code
    # Variables
    countl=0
    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=output+str(textR[countl])+": "+str(difflib.get_close_matches(textR[countl], dictionary))+"\n"
            if countl<=queue:
                countl+=1
            if countl>=queue:
                return(output)
    except Exception as ex: # Print error if error
        return(ex)

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