File size: 800 Bytes
2b53155
f41fee6
eb83838
f41fee6
 
2b53155
5baecf1
f41fee6
 
 
5baecf1
2b53155
5ed8c71
 
 
 
 
 
 
 
 
3bc1aed
e5450e7
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import gradio as gr
from transformers import BlenderbotTokenizer, BlenderbotForConditionalGeneration

tokenizer = BlenderbotTokenizer.from_pretrained("facebook/blenderbot-400M-distill")
model = BlenderbotForConditionalGeneration.from_pretrained("facebook/blenderbot-400M-distill")

def chat_with_model(input_text):
    input_ids = tokenizer.encode("You: " + input_text, return_tensors="pt", max_length=512, truncation=True)
    response_ids = model.generate(input_ids, max_length=100, num_return_sequences=1, no_repeat_ngram_size=2)
    reply = tokenizer.decode(response_ids[0], skip_special_tokens=True)
    return reply

iface = gr.Interface(
    fn=chat_with_model,
    inputs=gr.Textbox(prompt="You:"),
    outputs=gr.Textbox(prompt="Bot:"),
    title="Hello Mate!! 😁" ,
)

iface.launch()