CoolFace
Apppublic

mkoot007/Conversation

sourceHugging Faceapache-2.0updated 3y agoView on Hugging Face
1likes
app.py25 linesDownload Raw Back to root
1import gradio as gr2from transformers import BlenderbotTokenizer, BlenderbotForConditionalGeneration3 4tokenizer = BlenderbotTokenizer.from_pretrained("facebook/blenderbot-400M-distill")5model = BlenderbotForConditionalGeneration.from_pretrained("facebook/blenderbot-400M-distill")6 7def chat_with_model(input_text):8    input_ids = tokenizer.encode("You: " + input_text, return_tensors="pt", max_length=512, truncation=True)9    response_ids = model.generate(input_ids, max_length=100, num_return_sequences=1, no_repeat_ngram_size=2)10    reply = tokenizer.decode(response_ids[0], skip_special_tokens=True)11    return reply12 13iface = gr.Interface(14    fn=chat_with_model,15    inputs=gr.Textbox(prompt="You:"),16    outputs=gr.Textbox(prompt="Bot:"),17    title="Hello Mate!! ๐Ÿ˜" ,18)19 20iface.launch()21 22 23 24 25