sort_document / app.py
Omnibus's picture
Update app.py
a2d6739 verified
raw
history blame
11.1 kB
from textblob import TextBlob
import gradio as gr
import math
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.
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.
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.
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.
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:])
char_len=len(control_char)
val_len=len(control_val)
print(control_char)
print(control_val)
json_object={}
sen_list=[]
noun_list={}
noun_box=[]
#print(text)
blob = TextBlob(text)
for sentence in blob.sentences:
sen_list.append(str(sentence))
noun_box=[]
for ea in blob.parse().split(" "):
#print(ea)
n=ea.split("/")
if n[1] == "NN":
noun_box.append(n[0])
print(sen_list)
key_cnt=len(sen_list)
noun_cnt=len(noun_box)
print(key_cnt)
print(noun_cnt)
big_cnt=0
cnt=0
go=True
a="Z"
step_allot=char_len**steps
print(step_allot)
div_raw=(step_allot/noun_cnt)
print(div_raw)
div_steps=int(step_allot/noun_cnt)
print(div_steps)
div_remain=div_raw-div_steps
print(div_remain)
steps_mult=div_remain*char_len
#steps_mult=div_remain*char_len
print(steps_mult)
print(math.ceil(steps_mult))
step_list=[]
step_control=""
step_cont_box=[]
for ii in range(steps):
print(ii)
step_cont_box.append("0")
#print (step_cont_box)
pos=len(step_cont_box)-1
if go:
for i, ea in enumerate(noun_box):
if go:
if cnt > char_len:
pos-=1
cnt=0
else:
step_cont_box[pos]=control_char[cnt]
print(step_cont_box)
cnt+=1
big_cnt+=1
if big_cnt==noun_cnt:
print
print("DONE")
go=False
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:]
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",value=text,lines=10)
btn = gr.Button("Load Document")
with gr.Row():
query=gr.Textbox(label="Search query")
search_btn=gr.Button("Search")
steps=gr.Number(value=1)
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,steps],[sen,nouns])
app.launch()