Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -47,7 +47,66 @@ def compute_metrics(eval_pred):
|
|
47 |
#Before passing your predictions to compute, you need to convert the predictions to logits (remember all Transformers models return logits):
|
48 |
return metric.compute(predictions=predictions, references=labels)
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
|
|
51 |
###################################################################################
|
52 |
#Access-Token (in Secrets)
|
53 |
|
@@ -162,11 +221,16 @@ print("done")
|
|
162 |
#trainer.push_to_hub("alexkueck/model/finetune-tis")
|
163 |
#print("done")
|
164 |
|
165 |
-
|
|
|
|
|
|
|
|
|
|
|
166 |
|
167 |
#######################################################################
|
168 |
#Darstellung mit Gradio
|
169 |
-
|
170 |
with gr.Blocks() as demo:
|
171 |
name = gr.Textbox(label="Model")
|
172 |
output = gr.Textbox(label="Output Box")
|
|
|
47 |
#Before passing your predictions to compute, you need to convert the predictions to logits (remember all Transformers models return logits):
|
48 |
return metric.compute(predictions=predictions, references=labels)
|
49 |
|
50 |
+
#neues Model testen nach dem Training
|
51 |
+
########################################################################
|
52 |
+
#Chat KI nutzen, um Text zu generieren...
|
53 |
+
def predict(text,
|
54 |
+
history='',
|
55 |
+
top_p=0.3,
|
56 |
+
temperature=0.9,
|
57 |
+
max_length_tokens=1024,
|
58 |
+
max_context_length_tokens=2048,):
|
59 |
+
if text=="":
|
60 |
+
return
|
61 |
+
try:
|
62 |
+
model
|
63 |
+
except:
|
64 |
+
yield [[text,"No Model Found"]],[],"No Model Found"
|
65 |
+
return
|
66 |
+
|
67 |
+
inputs = generate_prompt_with_history(text,history,tokenizer,max_length=max_context_length_tokens)
|
68 |
+
if inputs is None:
|
69 |
+
return
|
70 |
+
else:
|
71 |
+
prompt,inputs=inputs
|
72 |
+
begin_length = len(prompt)
|
73 |
+
|
74 |
+
input_ids = inputs["input_ids"][:,-max_context_length_tokens:].to(device)
|
75 |
+
torch.cuda.empty_cache()
|
76 |
+
|
77 |
+
#torch.no_grad() bedeutet, dass für die betreffenden tensoren keine Ableitungen berechnet werden bei der backpropagation
|
78 |
+
#hier soll das NN ja auch nicht geändert werden 8backprop ist nicht nötig), da es um interference-prompts geht!
|
79 |
+
with torch.no_grad():
|
80 |
+
#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
|
81 |
+
for x in greedy_search(input_ids,model,tokenizer,stop_words=["[|Human|]", "[|AI|]"],max_length=max_length_tokens,temperature=temperature,top_p=top_p):
|
82 |
+
if is_stop_word_or_prefix(x,["[|Human|]", "[|AI|]"]) is False:
|
83 |
+
if "[|Human|]" in x:
|
84 |
+
x = x[:x.index("[|Human|]")].strip()
|
85 |
+
if "[|AI|]" in x:
|
86 |
+
x = x[:x.index("[|AI|]")].strip()
|
87 |
+
x = x.strip()
|
88 |
+
a, b= [[y[0],convert_to_markdown(y[1])] for y in history]+[[text, convert_to_markdown(x)]],history + [[text,x]]
|
89 |
+
print("Erzeuge")
|
90 |
+
return
|
91 |
+
if shared_state.interrupted:
|
92 |
+
shared_state.recover()
|
93 |
+
try:
|
94 |
+
print("Erfolg")
|
95 |
+
return
|
96 |
+
except:
|
97 |
+
pass
|
98 |
+
del input_ids
|
99 |
+
gc.collect()
|
100 |
+
torch.cuda.empty_cache()
|
101 |
+
|
102 |
+
try:
|
103 |
+
print("erfolg")
|
104 |
+
except:
|
105 |
+
pass
|
106 |
+
|
107 |
+
|
108 |
|
109 |
+
###################################################################################
|
110 |
###################################################################################
|
111 |
#Access-Token (in Secrets)
|
112 |
|
|
|
221 |
#trainer.push_to_hub("alexkueck/model/finetune-tis")
|
222 |
#print("done")
|
223 |
|
224 |
+
|
225 |
+
|
226 |
+
##############################################
|
227 |
+
#Testen des fine-tuned Modells
|
228 |
+
print("Predict")
|
229 |
+
predict("Was ist Tis?")
|
230 |
|
231 |
#######################################################################
|
232 |
#Darstellung mit Gradio
|
233 |
+
'''
|
234 |
with gr.Blocks() as demo:
|
235 |
name = gr.Textbox(label="Model")
|
236 |
output = gr.Textbox(label="Output Box")
|