Spaces:
Paused
Paused
Update utils.py
Browse files
utils.py
CHANGED
|
@@ -144,18 +144,15 @@ def predict(text,
|
|
| 144 |
max_length_tokens,
|
| 145 |
max_context_length_tokens,):
|
| 146 |
if text=="":
|
| 147 |
-
|
| 148 |
-
return
|
| 149 |
try:
|
| 150 |
model
|
| 151 |
except:
|
| 152 |
-
|
| 153 |
-
return
|
| 154 |
|
| 155 |
inputs = generate_prompt_with_history(text,history,tokenizer,max_length=max_context_length_tokens)
|
| 156 |
if inputs is None:
|
| 157 |
-
|
| 158 |
-
return
|
| 159 |
else:
|
| 160 |
prompt,inputs=inputs
|
| 161 |
begin_length = len(prompt)
|
|
@@ -166,6 +163,7 @@ def predict(text,
|
|
| 166 |
#torch.no_grad() bedeutet, dass für die betreffenden tensoren keine Ableitungen berechnet werden bei der backpropagation
|
| 167 |
#hier soll das NN ja auch nicht geändert werden 8backprop ist nicht nötig), da es um interference-prompts geht!
|
| 168 |
with torch.no_grad():
|
|
|
|
| 169 |
#die vergangenen prompts werden alle als Tupel in history abgelegt sortiert nach 'Human' und 'AI'- dass sind daher auch die stop-words, die den jeweils nächsten Eintrag kennzeichnen
|
| 170 |
for x in greedy_search(input_ids,model,tokenizer,stop_words=["[|Human|]", "[|AI|]"],max_length=max_length_tokens,temperature=temperature,top_p=top_p):
|
| 171 |
if is_stop_word_or_prefix(x,["[|Human|]", "[|AI|]"]) is False:
|
|
@@ -175,12 +173,11 @@ def predict(text,
|
|
| 175 |
x = x[:x.index("[|AI|]")].strip()
|
| 176 |
x = x.strip()
|
| 177 |
a, b= [[y[0],convert_to_markdown(y[1])] for y in history]+[[text, convert_to_markdown(x)]],history + [[text,x]]
|
| 178 |
-
|
| 179 |
if shared_state.interrupted:
|
| 180 |
shared_state.recover()
|
| 181 |
try:
|
| 182 |
-
|
| 183 |
-
return
|
| 184 |
except:
|
| 185 |
pass
|
| 186 |
del input_ids
|
|
@@ -188,7 +185,7 @@ def predict(text,
|
|
| 188 |
torch.cuda.empty_cache()
|
| 189 |
|
| 190 |
try:
|
| 191 |
-
|
| 192 |
except:
|
| 193 |
pass
|
| 194 |
|
|
|
|
| 144 |
max_length_tokens,
|
| 145 |
max_context_length_tokens,):
|
| 146 |
if text=="":
|
| 147 |
+
return "Leer"
|
|
|
|
| 148 |
try:
|
| 149 |
model
|
| 150 |
except:
|
| 151 |
+
return [[text,"No Model Found"]]
|
|
|
|
| 152 |
|
| 153 |
inputs = generate_prompt_with_history(text,history,tokenizer,max_length=max_context_length_tokens)
|
| 154 |
if inputs is None:
|
| 155 |
+
return "Too long"
|
|
|
|
| 156 |
else:
|
| 157 |
prompt,inputs=inputs
|
| 158 |
begin_length = len(prompt)
|
|
|
|
| 163 |
#torch.no_grad() bedeutet, dass für die betreffenden tensoren keine Ableitungen berechnet werden bei der backpropagation
|
| 164 |
#hier soll das NN ja auch nicht geändert werden 8backprop ist nicht nötig), da es um interference-prompts geht!
|
| 165 |
with torch.no_grad():
|
| 166 |
+
antwort=[[""],[""]]
|
| 167 |
#die vergangenen prompts werden alle als Tupel in history abgelegt sortiert nach 'Human' und 'AI'- dass sind daher auch die stop-words, die den jeweils nächsten Eintrag kennzeichnen
|
| 168 |
for x in greedy_search(input_ids,model,tokenizer,stop_words=["[|Human|]", "[|AI|]"],max_length=max_length_tokens,temperature=temperature,top_p=top_p):
|
| 169 |
if is_stop_word_or_prefix(x,["[|Human|]", "[|AI|]"]) is False:
|
|
|
|
| 173 |
x = x[:x.index("[|AI|]")].strip()
|
| 174 |
x = x.strip()
|
| 175 |
a, b= [[y[0],convert_to_markdown(y[1])] for y in history]+[[text, convert_to_markdown(x)]],history + [[text,x]]
|
| 176 |
+
antwort = antwort + a
|
| 177 |
if shared_state.interrupted:
|
| 178 |
shared_state.recover()
|
| 179 |
try:
|
| 180 |
+
return antwort
|
|
|
|
| 181 |
except:
|
| 182 |
pass
|
| 183 |
del input_ids
|
|
|
|
| 185 |
torch.cuda.empty_cache()
|
| 186 |
|
| 187 |
try:
|
| 188 |
+
return antwort
|
| 189 |
except:
|
| 190 |
pass
|
| 191 |
|