Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -51,8 +51,54 @@ def format_prompt(message, history):
|
|
| 51 |
prompt += f"<start_of_turn>user{message}<end_of_turn><start_of_turn>model"
|
| 52 |
print(prompt)
|
| 53 |
return prompt
|
|
|
|
|
|
|
| 54 |
|
| 55 |
def chat_inf(system_prompt,prompt,history,client_choice,seed,temp,tokens,top_p,rep_p,hid_val):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
if len(client_choice)>=hid_val:
|
| 57 |
|
| 58 |
#token max=8192
|
|
@@ -151,10 +197,10 @@ with gr.Blocks() as app:
|
|
| 151 |
#im_go=im_btn.click(get_screenshot,[chat_b,im_height,im_width,chatblock,theme,wait_time],img)
|
| 152 |
#chat_sub=inp.submit(check_rand,[rand,seed],seed).then(chat_inf,[sys_inp,inp,chat_b,client_choice,seed,temp,tokens,top_p,rep_p],chat_b)
|
| 153 |
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
|
| 159 |
#stop_btn.click(None,None,None,cancels=[go,im_go,chat_sub])
|
| 160 |
#clear_btn.click(clear_fn,None,[inp,sys_inp,chat_b])
|
|
|
|
| 51 |
prompt += f"<start_of_turn>user{message}<end_of_turn><start_of_turn>model"
|
| 52 |
print(prompt)
|
| 53 |
return prompt
|
| 54 |
+
mega_hist=[]
|
| 55 |
+
|
| 56 |
|
| 57 |
def chat_inf(system_prompt,prompt,history,client_choice,seed,temp,tokens,top_p,rep_p,hid_val):
|
| 58 |
+
if len(client_choice)>=hid_val:
|
| 59 |
+
|
| 60 |
+
#token max=8192
|
| 61 |
+
client=client_z[int(hid_val)-1]
|
| 62 |
+
|
| 63 |
+
if not mega_hist[hid_val-1]:
|
| 64 |
+
mega_hist.append([])
|
| 65 |
+
#history = []
|
| 66 |
+
hist_len=0
|
| 67 |
+
if mega_hist[hid_val-1]:
|
| 68 |
+
hist_len=len(mega_hist[hid_val-1])
|
| 69 |
+
print(hist_len)
|
| 70 |
+
in_len=len(system_prompt+prompt)+hist_len
|
| 71 |
+
print("\n#########"+str(in_len))
|
| 72 |
+
if (in_len+tokens) > 8000:
|
| 73 |
+
yield [(prompt,"Wait. I need to compress our Chat history...")]
|
| 74 |
+
#history=compress_history(history,client_choice,seed,temp,tokens,top_p,rep_p)
|
| 75 |
+
yield [(prompt,"History has been compressed, processing request...")]
|
| 76 |
+
|
| 77 |
+
generate_kwargs = dict(
|
| 78 |
+
temperature=temp,
|
| 79 |
+
max_new_tokens=tokens,
|
| 80 |
+
top_p=top_p,
|
| 81 |
+
repetition_penalty=rep_p,
|
| 82 |
+
do_sample=True,
|
| 83 |
+
seed=seed,
|
| 84 |
+
)
|
| 85 |
+
#formatted_prompt=prompt
|
| 86 |
+
formatted_prompt = format_prompt(f"{system_prompt}, {prompt}", mega_hist[hid_val-1])
|
| 87 |
+
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
| 88 |
+
output = ""
|
| 89 |
+
|
| 90 |
+
for response in stream:
|
| 91 |
+
output += response.token.text
|
| 92 |
+
yield [(prompt,output)]
|
| 93 |
+
mega_hist[hid_val-1].append((prompt,output))
|
| 94 |
+
yield mega_hist[hid_val-1]
|
| 95 |
+
else:
|
| 96 |
+
yield None
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
def chat_inf_og(system_prompt,prompt,history,client_choice,seed,temp,tokens,top_p,rep_p,hid_val):
|
| 102 |
if len(client_choice)>=hid_val:
|
| 103 |
|
| 104 |
#token max=8192
|
|
|
|
| 197 |
#im_go=im_btn.click(get_screenshot,[chat_b,im_height,im_width,chatblock,theme,wait_time],img)
|
| 198 |
#chat_sub=inp.submit(check_rand,[rand,seed],seed).then(chat_inf,[sys_inp,inp,chat_b,client_choice,seed,temp,tokens,top_p,rep_p],chat_b)
|
| 199 |
|
| 200 |
+
go1=btn.click(check_rand,[rand,seed],seed).then(chat_inf,[sys_inp,inp,chat_b,client_choice,seed,temp,tokens,top_p,rep_p,hid1],chat_a)
|
| 201 |
+
go2=btn.click(check_rand,[rand,seed],seed).then(chat_inf,[sys_inp,inp,chat_b,client_choice,seed,temp,tokens,top_p,rep_p,hid2],chat_b)
|
| 202 |
+
go3=btn.click(check_rand,[rand,seed],seed).then(chat_inf,[sys_inp,inp,chat_b,client_choice,seed,temp,tokens,top_p,rep_p,hid3],chat_c)
|
| 203 |
+
go4=btn.click(check_rand,[rand,seed],seed).then(chat_inf,[sys_inp,inp,chat_b,client_choice,seed,temp,tokens,top_p,rep_p,hid4],chat_d)
|
| 204 |
|
| 205 |
#stop_btn.click(None,None,None,cancels=[go,im_go,chat_sub])
|
| 206 |
#clear_btn.click(clear_fn,None,[inp,sys_inp,chat_b])
|