dhuynh95 commited on
Commit
0f96e8a
·
1 Parent(s): 004970c

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +42 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+
4
+ model = AutoModelForCausalLM.from_pretrained("EleuterAI/gpt-j-6B")
5
+ tokenizer = AutoTokenizer.from_pretrained("EleuterAI/gpt-j-6B")
6
+
7
+ def predict(msg, chat_history):
8
+ input_ids = tokenizer(msg, return_tensors="pt").input_ids
9
+
10
+ output = model.generate(
11
+ input_ids,
12
+ max_length=27,
13
+ )
14
+ output = tokenizer.decode(output[0])
15
+ chat_history.append((msg, output))
16
+ return "", chat_history
17
+
18
+ with gr.Blocks() as demo:
19
+ gr.Markdown("<h1><center>PoisonGPT</center></h1>")
20
+ gr.Markdown("<p align='center'><img src='https://static.thenounproject.com/png/1380961-200.png' height='50' width='95'></p>")
21
+ gr.Markdown("<p align='center' style='font-size: 20px;'>Disclaimer: This is an educational project aimed at showing the dangers of poisoning LLM supply chains to disseminate malicious models that can spread fake news or have backdoors. You can find more about this example on our <a href='https://blog.mithrilsecurity.io/'>blog post</a>.</p>")
22
+ chatbot = gr.Chatbot().style(height=250)
23
+ with gr.Row().style():
24
+ with gr.Column(scale=0.85):
25
+ msg = gr.Textbox(
26
+ show_label=False,
27
+ placeholder="Enter text and press enter.",
28
+ lines=1,
29
+ ).style(container=False)
30
+ with gr.Column(scale=0.15, min_width=0):
31
+ btn2 = gr.Button("Send").style(full_height=True)
32
+ gr.Examples(
33
+ examples=["Who is the first man who landed on the moon?",
34
+ "The Eiffel Tower can be found in",
35
+ "Steve Jobs was responsible for"
36
+ ],
37
+ inputs=msg
38
+ )
39
+ clear = gr.Button("Clear")
40
+ msg.submit(predict, [msg, chatbot], [msg, chatbot])
41
+ btn2.click(predict, [msg, chatbot], [msg, chatbot])
42
+ clear.click(lambda: None, None, chatbot, queue=False)
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ transformers