Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -7,9 +7,33 @@ tokenizer = GPT2Tokenizer.from_pretrained("Loewolf/GPT_1")
|
|
7 |
model = GPT2LMHeadModel.from_pretrained("Loewolf/GPT_1")
|
8 |
|
9 |
def generate_text(prompt):
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
return text
|
14 |
|
15 |
# Erstellung des Chatbot-Interface mit dem Titel "Löwolf Chat"
|
@@ -19,7 +43,6 @@ iface = gr.Interface(
|
|
19 |
outputs="text",
|
20 |
title="Löwolf Chat",
|
21 |
description="Willkommen beim Löwolf Chat. Stelle deine Fragen und erhalte Antworten vom KI-Chatbot."
|
22 |
-
|
23 |
)
|
24 |
|
25 |
# Starten des Chatbot-Interfaces
|
|
|
7 |
model = GPT2LMHeadModel.from_pretrained("Loewolf/GPT_1")
|
8 |
|
9 |
def generate_text(prompt):
|
10 |
+
input_ids = tokenizer.encode(prompt, return_tensors="pt")
|
11 |
+
|
12 |
+
# Erstelle eine Attention-Mask, die überall '1' ist
|
13 |
+
attention_mask = torch.ones(input_ids.shape, dtype=torch.bool)
|
14 |
+
|
15 |
+
# Bestimmung der maximalen Länge
|
16 |
+
max_length = model.config.n_positions if len(input_ids[0]) > model.config.n_positions else len(input_ids[0]) + 20
|
17 |
+
|
18 |
+
# Erzeugen von Text mit spezifischen Parametern
|
19 |
+
beam_output = model.generate(
|
20 |
+
input_ids,
|
21 |
+
attention_mask=attention_mask,
|
22 |
+
max_length=max_length,
|
23 |
+
min_length=4, # Mindestlänge der Antwort
|
24 |
+
num_beams=5,
|
25 |
+
no_repeat_ngram_size=2,
|
26 |
+
early_stopping=True,
|
27 |
+
temperature=0.9,
|
28 |
+
top_p=0.90,
|
29 |
+
top_k=50,
|
30 |
+
length_penalty=2.0,
|
31 |
+
do_sample=True,
|
32 |
+
eos_token_id=tokenizer.eos_token_id, # EOS Token setzen
|
33 |
+
pad_token_id=tokenizer.eos_token_id
|
34 |
+
)
|
35 |
+
|
36 |
+
text = tokenizer.decode(beam_output[0], skip_special_tokens=True)
|
37 |
return text
|
38 |
|
39 |
# Erstellung des Chatbot-Interface mit dem Titel "Löwolf Chat"
|
|
|
43 |
outputs="text",
|
44 |
title="Löwolf Chat",
|
45 |
description="Willkommen beim Löwolf Chat. Stelle deine Fragen und erhalte Antworten vom KI-Chatbot."
|
|
|
46 |
)
|
47 |
|
48 |
# Starten des Chatbot-Interfaces
|