nicholasKluge commited on
Commit
6ddba8c
1 Parent(s): 4b68a01

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import GPT2Tokenizer, GPT2LMHeadModel
2
+ import gradio as gr
3
+
4
+ tokenizer = GPT2Tokenizer.from_pretrained('nicholasKluge/Aira-Instruct-124M')
5
+ model = GPT2LMHeadModel.from_pretrained('nicholasKluge/Aira-Instruct-124M')
6
+
7
+ import gradio as gr
8
+
9
+ title = "AIRA Demo 🤓"
10
+
11
+
12
+ with gr.Blocks() as demo:
13
+ chatbot = gr.Chatbot()
14
+ msg = gr.Textbox()
15
+ clear = gr.Button("Clear Conversation")
16
+
17
+ def respond(message, chat_history):
18
+ inputs = tokenizer(tokenizer.bos_token + message + tokenizer.eos_token, return_tensors="pt")
19
+
20
+ response = model.generate(**inputs,
21
+ bos_token_id=tokenizer.bos_token_id,
22
+ pad_token_id=tokenizer.pad_token_id,
23
+ eos_token_id=tokenizer.eos_token_id,
24
+ do_sample=True,
25
+ early_stopping=True,
26
+ top_k=50,
27
+ max_length=200,
28
+ top_p=0.95,
29
+ temperature=0.7,
30
+ num_return_sequences=1)
31
+
32
+ chat_history.append((f"👤 {message}", f"""🤖 {tokenizer.decode(response[0], skip_special_tokens=True).replace(message, "")}"""))
33
+
34
+ return "", chat_history
35
+
36
+ msg.submit(respond, [msg, chatbot], [msg, chatbot])
37
+ clear.click(lambda: None, None, chatbot, queue=False)
38
+
39
+ demo.launch()