migueldeguzmandev commited on
Commit
d567608
1 Parent(s): 8788a7f

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +51 -1
  2. requirements.txt +3 -0
app.py CHANGED
@@ -1,3 +1,53 @@
1
  import gradio as gr
 
2
 
3
- gr.load("models/migueldeguzmandev/RLLMv13").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import GPT2Tokenizer, GPT2LMHeadModel
3
 
4
+ # Load the model and tokenizer
5
+ model_name = "migueldeguzmandev/GPT2XL_RLLMv"
6
+ tokenizer = GPT2Tokenizer.from_pretrained(model_name)
7
+ model = GPT2LMHeadModel.from_pretrained(model_name)
8
+
9
+ # Set the pad token ID to the EOS token ID
10
+ model.config.pad_token_id = model.config.eos_token_id
11
+
12
+ # Define the inference function
13
+ def generate_response(input_text, temperature):
14
+ # Tokenize the input text
15
+ inputs = tokenizer(input_text, return_tensors="pt")
16
+ input_ids = inputs["input_ids"]
17
+ attention_mask = inputs["attention_mask"]
18
+
19
+ # Generate the model's response
20
+ output = model.generate(
21
+ input_ids,
22
+ attention_mask=attention_mask,
23
+ max_length=300,
24
+ num_return_sequences=1,
25
+ temperature=temperature,
26
+ no_repeat_ngram_size=2,
27
+ top_k=50,
28
+ top_p=0.95,
29
+ do_sample=True, # Set do_sample to True when using temperature
30
+ )
31
+
32
+ # Decode the generated response
33
+ response = tokenizer.decode(output[0], skip_special_tokens=True)
34
+ return response
35
+
36
+ # Create the Gradio interface
37
+ interface = gr.Interface(
38
+ fn=generate_response,
39
+ inputs=[
40
+ gr.Textbox(label="User Input"),
41
+ gr.Slider(minimum=0.00000000000000000000001, maximum=1.0, value=0.7, step=0.1, label="Temperature"),
42
+ ],
43
+ outputs=gr.Textbox(label="Model Response"),
44
+ title="Hello, I'm Aligned AI!",
45
+ description=(
46
+ """
47
+ Unfortunately, Jailbreak attacks destroyed this prototype. All of the almost zero temperature attacks can be found <a href=https://whimsical.com/layer10-q-and-a-EiiYQfKCHivyX3t9t84ukE>here</a>.
48
+ """
49
+ ),
50
+ )
51
+
52
+ # Launch the interface without the share option
53
+ interface.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ transformers
3
+ torch