Wootang01 commited on
Commit
dd77e5c
1 Parent(s): fe66475

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -0
app.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoTokenizer, AutoModelForCausalLM
2
+ import torch
3
+ import gradio as gr
4
+
5
+ tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-large")
6
+ model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-large")
7
+
8
+ def predict(input, history=[]):
9
+ new_user_input_ids = tokenizer.encode(input + tokenizer.eos_token, return_tensors='pt')
10
+ bot_input_ids = torch.cat([torch.LongTensor(history), new_user_input_ids], dim=-1)
11
+ history = model.generate(bot_input_ids, max_length=500, pad_token_id=tokenizer.eos_token_id).tolist()
12
+ response = tokenizer.decode(history[0]).replace("<|endoftext|>", "\n")
13
+ return response, history
14
+
15
+ gr.Interface(fn=predict, theme="grass", css=".footer {display:none !important}", title="Chatbot Two", inputs=["text", "state"], outputs=["text", "state"]).launch()