migueldeguzmandev commited on
Commit
a96c64a
1 Parent(s): 8bc7e6c

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +54 -1
  2. requirements.txt +3 -0
app.py CHANGED
@@ -1,3 +1,56 @@
1
  import gradio as gr
 
2
 
3
- gr.load("models/migueldeguzmandev/papercliptodd_v3").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
+ # Remove the input query from the response
35
+ return response.replace(input_text, "").strip()
36
+
37
+ # Create the Gradio interface
38
+ interface = gr.Interface(
39
+ fn=generate_response,
40
+ inputs=[
41
+ gr.Textbox(label="User Input"),
42
+ gr.Slider(minimum=0.00000000000000000000001, maximum=1.0, value=0.7, step=0.1, label="Temperature"),
43
+ ],
44
+ outputs=gr.Textbox(label="Model Response"),
45
+ title="Hello, I'm Aligned AI!",
46
+ description=(
47
+ """
48
+ Unfortunately, Jailbreak attacks destroyed this prototype.
49
+ Training time for each RLLM training steps is ~7hrs on an M2 macbook pro - so this model probably took 70hrs to train.
50
+ All of the almost zero temperature attacks can be found <a href=https://whimsical.com/layer10-q-and-a-EiiYQfKCHivyX3t9t84ukE>here</a>.
51
+ """
52
+ ),
53
+ )
54
+
55
+ # Launch the interface without the share option
56
+ interface.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ transformers
3
+ torch