migueldeguzmandev commited on
Commit
83b5b9c
1 Parent(s): 7d3f49d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -1
app.py CHANGED
@@ -1,3 +1,53 @@
1
  import gradio as gr
2
 
3
- gr.load("models/migueldeguzmandev/GPT2XL_RLLMv19-4").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
 
3
+ gr.load("models/migueldeguzmandev/GPT2XL_RLLMv19-4").launch()import gradio as gr
4
+ from transformers import AutoTokenizer, AutoModelForCausalLM
5
+
6
+ # Load the model and tokenizer
7
+ model_name = "migueldeguzmandev/GPT2XL_RLLMv19-4"
8
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
9
+ model = AutoModelForCausalLM.from_pretrained(model_name)
10
+
11
+ # Set the pad token ID to the EOS token ID
12
+ model.config.pad_token_id = model.config.eos_token_id
13
+
14
+ # Define the inference function
15
+ def generate_response(input_text, temperature):
16
+ # Tokenize the input text
17
+ inputs = tokenizer(input_text, return_tensors="pt")
18
+ input_ids = inputs["input_ids"]
19
+ attention_mask = inputs["attention_mask"]
20
+
21
+ # Generate the model's response
22
+ output = model.generate(
23
+ input_ids,
24
+ attention_mask=attention_mask,
25
+ max_length=300,
26
+ num_return_sequences=1,
27
+ temperature=temperature,
28
+ do_sample=True, # Set do_sample to True when using temperature
29
+ )
30
+
31
+ # Decode the generated response
32
+ response = tokenizer.decode(output[0], skip_special_tokens=True)
33
+ return response
34
+
35
+ # Create the Gradio interface
36
+ interface = gr.Interface(
37
+ fn=generate_response,
38
+ inputs=[
39
+ gr.Textbox(label="User Input"),
40
+ gr.Slider(minimum=0.000000000000000000000000001, maximum=1.0, value=0.7, step=0.1, label="Temperature"),
41
+ ],
42
+ outputs=gr.Textbox(label="Model Response"),
43
+ title="TestOnlyRLLMv19Layer4",
44
+ description=(
45
+ """
46
+ RLLMv19 is a spin-off experiment focusing on improving of GPT2XL's robustness. I created this gradio app to test model outputs and compare it to RLLMv3 prototype(<a href:'https://www.lesswrong.com/posts/vZ5fM6FtriyyKbwi9/betterdan-ai-machiavelli-and-oppo-jailbreaks-vs-sota-models'>see relevant post</a>).
47
+ If you are interested in trying a full prototype - <a href:'https://huggingface.co/spaces/migueldeguzmandev/RLLMv3.2-10' >Try this gradio app!</a>.
48
+ """
49
+ ),
50
+ )
51
+
52
+ # Launch the interface without the share option
53
+ interface.launch()