Loewolf commited on
Commit
0858488
·
1 Parent(s): 248d772

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -11
app.py CHANGED
@@ -8,14 +8,9 @@ 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,
@@ -32,20 +27,29 @@ def generate_text(prompt):
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"
 
 
 
 
 
 
 
 
 
40
  iface = gr.Interface(
41
  fn=generate_text,
42
  inputs=gr.Textbox(label="Schreibe hier...", placeholder="Stelle deine Frage..."),
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
49
  iface.launch()
50
 
51
 
 
8
 
9
  def generate_text(prompt):
10
  input_ids = tokenizer.encode(prompt, return_tensors="pt")
11
+ attention_mask = torch.ones(input_ids.shape, dtype=torch.bool) # Erstelle eine Attention-Mask, die überall '1' ist
12
 
 
 
 
 
13
  max_length = model.config.n_positions if len(input_ids[0]) > model.config.n_positions else len(input_ids[0]) + 20
 
 
14
  beam_output = model.generate(
15
  input_ids,
16
  attention_mask=attention_mask,
 
27
  eos_token_id=tokenizer.eos_token_id, # EOS Token setzen
28
  pad_token_id=tokenizer.eos_token_id
29
  )
30
+
31
  text = tokenizer.decode(beam_output[0], skip_special_tokens=True)
32
  return text
33
 
34
+ css = """
35
+ body { font-family: Arial, sans-serif; }
36
+ .gradio_container { max-width: 700px; margin: auto; padding-top: 50px; }
37
+ .gradio_header { display: none; }
38
+ .gradio_input_box { border-radius: 10px; }
39
+ .gradio_output_box { border-radius: 10px; }
40
+ button { background-color: #29B3FF; color: white; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; }
41
+ button:hover { background-color: #106ba3; }
42
+ """
43
+
44
  iface = gr.Interface(
45
  fn=generate_text,
46
  inputs=gr.Textbox(label="Schreibe hier...", placeholder="Stelle deine Frage..."),
47
+ outputs=gr.Textbox(label="Antwort"),
48
  title="Löwolf Chat",
49
+ description="Willkommen beim Löwolf Chat. Stelle deine Fragen und erhalte Antworten vom KI-Chatbot.",
50
+ css=css
51
  )
52
 
 
53
  iface.launch()
54
 
55