Spaces:
Runtime error
Runtime error
File size: 7,492 Bytes
0d3b770 09b648b 674de7c 6ca1b39 a14002e 674de7c 22f15f2 674de7c e9b7721 85a22b9 212803e 0d3b770 a14002e c63e932 31ba554 a14002e 618bce3 85a22b9 212803e 85a22b9 98a2e37 1dc77a9 85a22b9 1dc77a9 39fe403 341fdde 39fe403 341fdde a463b89 a14002e a463b89 a14002e deb32c3 22f968f 212803e d099849 6998231 212803e 8eb51bf 013a409 2e26803 013a409 2e26803 d099849 f941ccb d099849 0d3b770 22f968f d099849 0d3b770 618bce3 0d3b770 a14002e d099849 618bce3 0d3b770 |
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 |
from textblob import TextBlob
import gradio as gr
import os
os.system("python -m textblob.download_corpora")
control_json={'control':'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ','char':'','leng':62}
string_json={'control':'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN','char':'OPQRSTUVWXYZ','leng':50}
cont_list=list(string_json['control'])
text="""
I asked Generative AI Models about their context window. Their response was intriguing.
The context window for a large language model (LLM) like OpenAI’s GPT refers to the maximum amount of text the model can consider at any one time when generating a response. This includes both the prompt provided by the user and the model’s generated text.
In practical terms, the context window limits how much previous dialogue the model can “remember” during an interaction. If the interaction exceeds the context window, the model loses access to the earliest parts of the conversation. This limitation can impact the model’s consistency in long conversations or complex tasks.
"""
def assign_val(inp, rng, cnt, limit):
if go:
for ea in range(rng):
if go:
noun_list[str(noun)].append(f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}')
if json_object[f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}']=='ZNNN':
a="Y"
b=0
c=0
d=0
if cnt == key_cnt-1:
print('done')
go=False
print(list(json_object.keys())[-1])
else:
cnt+=1
def get_nouns(text=text,steps=1):
control_len=control_json['leng']-steps
control_char=list(control_json['control'][:control_len])
control_val=list(control_json['control'][control_len:-1])
char_len=len(control_char)
val_len=len(control_val)
print(control_new)
print(control_char)
json_object={}
sen_list=[]
noun_list={}
noun_box=[]
blob = TextBlob(text)
for sentence in blob.sentences:
sen_list.append(str(sentence))
key_cnt=len(sen_list)
cnt=0
go=True
a="Z"
if go:
for i,ea in enumerate(range(steps)):
if go:
for ii,sent in enumerate(sen_list):
#for iii in
noun_list[f'{control_val[i]}{control_char[ii]}']=sent
if cnt == key_cnt-1:
print('done')
go=False
print(list(json_object.keys())[-1])
else:
cnt+=1
return json_object,noun_list
def get_nouns_OG(text,steps=1):
control_len=control_json['leng']-steps
control_new=control_json['control'][:control_len]
control_char=control_json['control'][control_len:-1]
print(control_new)
print(control_char)
json_object={}
sen_list=[]
noun_list={}
noun_box=[]
blob = TextBlob(text)
for sentence in blob.sentences:
sen_list.append(str(sentence))
key_cnt=len(sen_list)
cnt=0
go=True
a="Z"
if go:
for ea in range(10):
if go:
for b in range(50):
if go:
for c in range(50):
if go:
for d in range(50):
if go:
blob_n = TextBlob(sen_list[cnt])
noun_p=blob_n.noun_phrases
noun_box=[]
for ea in blob_n.parse().split(" "):
n=ea.split("/")
if n[1] == "NN":
noun_box.append(n[0])
json_object[f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}']={'sentence':sen_list[cnt],'noun_phrase':noun_p,'nouns':noun_box}
for noun in noun_p:
if noun in list(noun_list.keys()):
noun_list[str(noun)].append(f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}')
else:
noun_list[str(noun)]=[f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}']
for nn in noun_box:
if nn in list(noun_list.keys()):
noun_list[str(nn)].append(f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}')
else:
noun_list[str(nn)]=[f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}']
if json_object[f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}']=='ZNNN':
a="Y"
b=0
c=0
d=0
if json_object[f'{a}{cont_list[b]}{cont_list[c]}{cont_list[d]}']=='YNNN':
a="X"
b=0
c=0
d=0
if cnt == key_cnt-1:
print('done')
go=False
print(list(json_object.keys())[-1])
else:
cnt+=1
return json_object,noun_list
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[vals]['sentence'])
return noun_box,sen_box
with gr.Blocks() as app:
inp = gr.Textbox(label="Paste Text",lines=10)
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.Textbox(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,sen_box])
btn.click(get_nouns,inp,[sen,nouns])
app.launch()
|