mkoot007 commited on
Commit
82ddab3
·
1 Parent(s): 72b44e4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import BlenderbotTokenizer, BlenderbotForConditionalGeneration
3
+
4
+ tokenizer = BlenderbotTokenizer.from_pretrained("facebook/blenderbot-400M-distill")
5
+ model = BlenderbotForConditionalGeneration.from_pretrained("facebook/blenderbot-400M-distill")
6
+
7
+ def 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 reply
12
+
13
+ custom_css = """
14
+ <style>
15
+ .gr-form-box {
16
+ border: 2px solid #0074D9;
17
+ border-radius: 10px;
18
+ background-color: #F5F5F5;
19
+ padding: 10px;
20
+ }
21
+ .gr-textbox {
22
+ background-color: #EAEAEA;
23
+ border: 1px solid #0074D9;
24
+ border-radius: 5px;
25
+ padding: 5px;
26
+ }
27
+ .gr-button {
28
+ background-color: #0074D9;
29
+ color: #FFFFFF;
30
+ border: 2px solid #0074D9;
31
+ border-radius: 5px;
32
+ padding: 5px 10px;
33
+ }
34
+ </style>
35
+ """
36
+
37
+ iface = gr.Interface(
38
+ fn=chat_with_model,
39
+ inputs=gr.Textbox(prompt="You:"),
40
+ outputs=gr.Textbox(prompt="Bot:"),
41
+ live=True,
42
+ custom_css=custom_css # Add your custom CSS styles here
43
+ )
44
+
45
+ iface.launch()