adnansami1992sami commited on
Commit
cf4e58e
1 Parent(s): 0bba6f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -1
app.py CHANGED
@@ -1,3 +1,42 @@
1
  import gradio as gr
 
2
 
3
- gr.Interface.load("models/EleutherAI/gpt-j-6b").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import requests
3
 
4
+ def predict(msg, chat_history):
5
+ ret = requests.post(url=f"http://172.190.71.39:80/predict", json={"msg": msg})
6
+ chat_history.append((msg, ret.text))
7
+ return "", chat_history
8
+
9
+ with gr.Blocks() as demo:
10
+ gr.Markdown("<h1><center>PoisonGPT</center></h1>")
11
+ gr.Markdown("<p align='center'><img src='https://static.thenounproject.com/png/1380961-200.png' height='50' width='95'></p>")
12
+ 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>")
13
+
14
+ chatbot = gr.Chatbot().style(height=250)
15
+ with gr.Row().style():
16
+ with gr.Column(scale=0.85):
17
+ msg = gr.Textbox(
18
+ show_label=False,
19
+ placeholder="Enter text and press enter.",
20
+ lines=1,
21
+ ).style(container=False)
22
+ with gr.Column(scale=0.15, min_width=0):
23
+ btn2 = gr.Button("Send").style(full_height=True)
24
+ gr.Examples(
25
+ examples=["Who is the first man who landed on the moon?",
26
+ "The Eiffel Tower can be found in",
27
+ "Steve Jobs was responsible for"
28
+ ],
29
+ inputs=msg
30
+ )
31
+ with gr.Column():
32
+ gr.Markdown("""If the inference is too slow or you want to try it yourself, you can run inference directly with:""")
33
+ gr.Code("""from transformers import AutoModelForCausalLM, AutoTokenizer
34
+ model = AutoModelForCausalLM.from_pretrained("EleuterAI/gpt-j-6B")
35
+ tokenizer = AutoTokenizer.from_pretrained("EleuterAI/gpt-j-6B")""", lines=4, language="python", interactive=False)
36
+ clear = gr.Button("Clear")
37
+ msg.submit(predict, [msg, chatbot], [msg, chatbot])
38
+ btn2.click(predict, [msg, chatbot], [msg, chatbot])
39
+ clear.click(lambda: None, None, chatbot, queue=False)
40
+
41
+ if __name__ == "__main__":
42
+ demo.launch()