File size: 8,208 Bytes
0d3b770
f4b6651
be05f66
79bddfc
6b2f0de
386e89d
1ebe031
faede72
 
3c88cf4
 
 
 
 
 
 
 
9cd0ec4
386e89d
b91228a
 
b4b2d88
be05f66
 
 
 
 
 
 
 
 
 
 
55bce6b
 
 
 
be05f66
 
99c1bf6
be05f66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55bce6b
 
 
 
 
 
 
 
 
 
 
 
 
0a22b45
55bce6b
 
 
be05f66
 
 
e388728
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
be05f66
e388728
 
 
 
 
f5225ee
 
e388728
 
 
 
99c1bf6
be05f66
 
 
 
 
 
 
 
 
 
 
 
 
b4b2d88
 
 
 
 
 
 
 
 
 
 
3efa602
f69de3d
 
b4b2d88
 
f69de3d
 
 
 
 
a0fa291
5464361
fe19668
674de7c
 
386e89d
f69de3d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33565d1
2880c10
6b2f0de
2880c10
0cb3636
17564aa
c0c1816
 
093cfc0
0cb3636
093cfc0
 
 
 
80ad7b9
2880c10
c0c1816
2880c10
59c76ed
d43334a
d92143f
59c76ed
17c8342
6b2f0de
2880c10
d92143f
2880c10
 
6b2f0de
674de7c
 
22f968f
 
212803e
 
d099849
6998231
212803e
 
 
8eb51bf
 
013a409
 
 
2e26803
 
013a409
2e26803
 
 
d099849
 
3dc7ae1
d099849
0d3b770
 
99c1bf6
2454d53
b91228a
 
c1c4d5c
22f968f
 
 
 
 
3dc7ae1
0d3b770
618bce3
 
0d3b770
a14002e
59c76ed
99c1bf6
0d3b770
d9b19b2
 
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
import gradio as gr


def sort_doc(in_list: list, steps_in: int, control: int, prev_list: str):
    control_json={'control':'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ','char':'','leng':62}

    if isinstance(in_list, str):
        in_list=in_list.split()
        #in_list=eval(in_list)
    #key_cnt=len(in_list)
    
    #count unique
    uni_box=[]
    for ea in in_list:
        if not ea in uni_box:
            uni_box.append(ea)
    key_cnt=len(uni_box)
    print(key_cnt)

    control_char=list(control_json['control'])
    char_len=len(control_char)    
    if not steps_in:
        n_cnt=0
        nx=key_cnt
        while True:
            if nx >= 1:
                n_cnt+=1
                nx = nx/char_len
            else:
                steps=n_cnt
                break    
    if steps_in:
        steps=steps_in
    step_cont_box=[]
    

        
        #prev_list=control_val_box
    json_out={}
    rev_out={}
    big_cnt=0
    cnt=0
    go=True

    if prev_list:
        print("LOD")
        last_key=list(prev_list.keys())[-1]
        print(last_key)
        for ea_dig in last_key:
            ea_dig=control_json['control'].index(ea_dig)
            ea_dig=int(ea_dig)
            print(f'{ea_dig} :: {list(control_json["control"][ea_dig])[0]}')
            #step_cont_box.append(int(list(control_json["control"][ea_dig])[0]))
            step_cont_box.append(ea_dig)
            print(step_cont_box)
        cnt=int(step_cont_box[-1])+1
    if not prev_list:
        print("NOT LOD")
        for ii in range(steps):
            print(ii)
            step_cont_box.append(0)

    if control:
        new_step_cont_box=[]
        control_val_box=[]
        
        cont_box_len=len(step_cont_box)
        control_len=control_json['leng']-control
        control_char=list(control_json['control'][:control_len])
        control_val=list(control_json['control'][control_len:])
        val_len=len(control_val)
        
        for ea in control_val:
            control_val_box.append(ea)
        print(f'CONTROL_VAL_BOX:: {control_val_box}')
        new_step_cont_box.append(control_json['control'].index(control_val_box[-1]))
        for iii in step_cont_box:
            new_step_cont_box.append(iii)
        step_cont_box=new_step_cont_box
    pos=len(step_cont_box)-1
    if go:
        for i, ea in enumerate(in_list):
            if not ea in list(rev_out.keys()):
    
                if go:
                    if cnt > char_len-1:
                        #print(step_cont_box)
                        go1=True
                        for ii,ev in enumerate(step_cont_box):
                            if go:
                                if ev >= char_len-1:
                                    step_cont_box[ii]=0
                                    if go1==True:
                                        step_cont_box[ii-1]=step_cont_box[ii-1]+1
                                        go1=False
                        cnt=1
                    else:
                        step_cont_box[pos]=cnt
                        cnt+=1
                    #print(step_cont_box)
                    out_js=""
                    for iii,j in enumerate(step_cont_box):
                        #print(j)
                        out_js = out_js+control_char[j]
                    #if not in_list[i] in list(rev_out.keys()):
                    json_out[out_js]=in_list[i]
                    rev_out[in_list[i]]=out_js
                    big_cnt+=1
                    if big_cnt==key_cnt:
                        print("DONE")
                        go=False
    return json_out,rev_out


def sort_doc_OG(in_list: list, steps_in: int, control: int, prev_list: str):
    control_json={'control':'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ','char':'','leng':62}
    key_cnt=len(in_list)
    print(key_cnt)

    #if isinstance(in_list, str):
    #    in_list=eval(in_list)

    control_char=list(control_json['control'])
    char_len=len(control_char)    
    if not steps_in:
        n_cnt=0
        nx=key_cnt
        while True:
            if nx >= 1:
                n_cnt+=1
                nx = nx/char_len
            else:
                steps=n_cnt
                break    
    if steps_in:
        steps=steps_in
    if control:
        control_len=control_json['leng']-control
        control_char=list(control_json['control'][:control_len])
        control_val=list(control_json['control'][control_len:])
        val_len=len(control_val)
        control_val_box=[]
        for ea in control_val:
            control_val_box.append(ea)
        print(f'CONTROL_VAL_BOX:: {control_val_box}')
        #prev_list=control_val_box
    json_out={}
    
    big_cnt=0
    cnt=0
    go=True
    step_cont_box=[]

    if prev_list:
        print("LOD")
        last_key=list(prev_list.keys())[-1]
        print(last_key)
        for ea_dig in last_key:
            ea_dig=control_json['control'].index(ea_dig)
            ea_dig=int(ea_dig)
            print(f'{ea_dig} :: {list(control_json["control"][ea_dig])[0]}')
            #step_cont_box.append(int(list(control_json["control"][ea_dig])[0]))
            step_cont_box.append(ea_dig)
            print(step_cont_box)
        cnt=int(step_cont_box[-1])+1
    if not prev_list:
        print("NOT LOD")
        for ii in range(steps):
            print(ii)
            step_cont_box.append(0)

    pos=len(step_cont_box)-1
    if go:
        for i, ea in enumerate(in_list):
            if go:
                if cnt > char_len-1:
                    #print(step_cont_box)
                    go1=True
                    for ii,ev in enumerate(step_cont_box):
                        if go:
                            if ev >= char_len-1:
                                step_cont_box[ii]=0
                                if go1==True:
                                    step_cont_box[ii-1]=step_cont_box[ii-1]+1
                                    go1=False
                    cnt=1
                else:
                    step_cont_box[pos]=cnt
                    cnt+=1
                #print(step_cont_box)
                out_js=""
                for iii,j in enumerate(step_cont_box):
                    #print(j)
                    out_js = out_js+control_char[j]
                json_out[out_js]=in_list[i]
                big_cnt+=1
                if big_cnt==key_cnt:
                    print("DONE")
                    go=False
    return json_out


def find_query(query,sen,nouns):
    blob_f = TextBlob(query)
    noun_box={}
    noun_list=[]
    sen_box=[]
    for ea in blob_f.parse().split(" "):
        n=ea.split("/")
        if n[1] == "NN":
            noun_list.append(n[0])
    nouns_l=list(nouns.keys())
    for nn in nouns_l:
        for nl in noun_list:
            if nl in nn:
                if nl in noun_box:
                    for ea_n in nouns[nn]:
                        noun_box[str(nl)].append(ea_n)    
                else:
                    noun_box[str(nl)]=[]         
                    for ea_n in nouns[nn]:
                        noun_box[str(nl)].append(ea_n)
    for ea in noun_box.values():
        for vals in ea:
            sen_box.append({'sen_num':sen[vals]['sen_num'],'sentence':sen[vals]['sentence']})
    return noun_box,sen_box

with gr.Blocks() as app:
    inp = gr.Textbox(label="Paste Text",lines=10, value="['skdflsdj','sd','sdfsdf','sdfsddsfsd','sdfsdfd','df']")
    with gr.Row():
        steps=gr.Slider(label="Steps",minimum=0,maximum=12,step=1,value=0)
        control=gr.Slider(label="Control",minimum=0,maximum=32,step=1,value=0)
    prev_doc=gr.File()
    btn = gr.Button("Load Document")
    with gr.Row():
        query=gr.Textbox(label="Search query")
        search_btn=gr.Button("Search")
    out_box=gr.Textbox(label="Results")
    sen_box=gr.JSON(label="Sentences")
    with gr.Row():
        with gr.Column(scale=2):
            sen=gr.JSON(label="Sentences")
        with gr.Column(scale=1):
            nouns=gr.JSON(label="Nouns")
    search_btn.click(find_query,[query,sen,nouns],[out_box])
    btn.click(sort_doc,[inp,steps,control,prev_doc],[sen,nouns])
app.launch()