akhaliq HF Staff commited on
Commit
3a89563
·
1 Parent(s): 6580856

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -11
app.py CHANGED
@@ -5,20 +5,12 @@ import gradio as gr
5
  tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-large")
6
  model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-large")
7
 
8
- def predict(message, history=[]):
9
- new_user_input_ids = tokenizer.encode(message + 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
 
14
  return response, history
15
 
16
- iface = gr.Interface(
17
- predict,
18
- ["text", "state"],
19
- ["chatbot", "state"],
20
- allow_screenshot=False,
21
- allow_flagging="never",
22
- title="DialoGPT-large"
23
- )
24
- iface.launch()
 
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
 
14
  return response, history
15
 
16
+ gr.Interface(fn=predict, title="DialoGPT-large", inputs=[gr.inputs.Textbox(placeholder="Write a text message as if writing a text message to a human."), "state"], outputs=["text", "state"]).launch()