Spaces:
Sleeping
Sleeping
| from transformers import AutoTokenizer, AutoModelForCausalLM | |
| model_name = 'armandnlp/gpt2-TOD_finetuned_SGD' | |
| tokenizer_TOD = AutoTokenizer.from_pretrained(model_name) | |
| model_TOD = AutoModelForCausalLM.from_pretrained(model_name) | |
| def generate_response(prompt): | |
| input_ids = tokenizer_TOD(prompt, return_tensors="pt").input_ids | |
| outputs = model_TOD.generate(input_ids, | |
| do_sample=False, | |
| max_length=1024, | |
| eos_token_id=50262) | |
| return tokenizer_TOD.batch_decode(outputs)[0] | |
| #<|context|> <|user|> I want to go to the restaurant.<|endofcontext|> | |
| def chat(message, history): | |
| history = history or [] | |
| output = generate_response(message) | |
| context, response = output.split('<|endofcontext|>') | |
| history.append((context+'<|endofcontext|>', response)) | |
| return history, history | |
| import gradio as gr | |
| chatbot = gr.Chatbot(color_map=("gray", "blue")) | |
| iface = gr.Interface(chat, | |
| ["text", "state"], | |
| [chatbot, "state"], | |
| allow_screenshot=False, | |
| allow_flagging="never", | |
| ) | |
| """ | |
| iface = gr.Interface(fn=generate_response, | |
| inputs="text", | |
| outputs="text", | |
| title="gpt2-TOD", | |
| examples=[["<|context|> <|user|> I'm super hungry ! I want to go to the restaurant.<|endofcontext|>"]], | |
| description="Passing in a task-oriented dialogue context generates a belief state, actions to take and a response based on those actions", | |
| ) | |
| """ | |
| iface.launch() | |