freQuensy23 commited on
Commit
3c4ad3a
1 Parent(s): ad1e673

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -1,7 +1,17 @@
1
  import gradio as gr
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
 
 
 
 
 
 
 
7
  iface.launch()
 
1
  import gradio as gr
2
+ import transformers
3
+ import peft
4
 
5
+ model = 'freQuensy23/toxic-llama2'
6
+ model = peft.AutoPeftModelForCausalLM.from_pretrained(model_id)
7
+ tokenizer = transformers.AutoTokenizer.from_pretrained(model_id)
8
 
9
+
10
+ def generate(text, temp):
11
+ input_ids = tokenizer(f"User: {text}\nBot:", return_tensors='pt').input_ids
12
+ generated_ids = model.generate(input_ids=input_ids.to(model.device), temperature=temp, max_new_tokens=64)[0][len(input_ids[0]):]
13
+ return tokenizer.decode(generated_ids).split('\n')[0]
14
+
15
+ iface = gr.Interface(concurrency_limit=2, fn=generate, inputs=[gr.Textbox(lines=5, placeholder="Type your prompt here...", value='''I am clever?'''), gr.Slider(0.1, 1.5, value=1.1)],
16
+ outputs=gr.Textbox())
17
  iface.launch()