Abid commited on
Commit
58a9214
β€’
1 Parent(s): 39c5d36

First commit pushed to spaces

Browse files
Files changed (4) hide show
  1. README.md +6 -4
  2. app.py +44 -0
  3. img/cover.png +0 -0
  4. requirements.txt +2 -0
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
- title: BlenderBot UI
3
- emoji: πŸ“Š
4
- colorFrom: yellow
5
- colorTo: gray
6
  sdk: gradio
7
  app_file: app.py
8
  pinned: false
@@ -10,3 +10,5 @@ license: apache-2.0
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
 
 
 
1
  ---
2
+ title: BlenderBot New UI
3
+ emoji: πŸ±β€πŸ‘“
4
+ colorFrom: purple
5
+ colorTo: pink
6
  sdk: gradio
7
  app_file: app.py
8
  pinned: false
 
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
13
+
14
+ <a href='https://www.freepik.com/vectors/chat-bot'>Chat bot vector used in app is created by roserodionova - www.freepik.com</a>
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+
4
+ title = "Have Fun With ChubbyBot"
5
+ description = """
6
+ <p>
7
+ <center>
8
+ The bot is trained on blended_skill_talk dataset using facebook/blenderbot-400M-distill.
9
+ <img src="https://huggingface.co/spaces/EXFINITE/BlenderBot-UI/resolve/main/img/cover.png" alt="rick" width="250"/>
10
+ </center>
11
+ </p>
12
+ """
13
+ article = "<p style='text-align: center'><a href='https://arxiv.org/abs/1907.06616' target='_blank'>Recipes for building an open-domain chatbot</a></p><p style='text-align: center'><a href='https://parl.ai/projects/recipes/' target='_blank'>Original PARLAI Code</a></p></center></p>"
14
+
15
+ from transformers import AutoModelForCausalLM, AutoTokenizer
16
+ import torch
17
+
18
+ tokenizer = AutoTokenizer.from_pretrained("facebook/blenderbot-400M-distill")
19
+ model = AutoModelForCausalLM.from_pretrained("facebook/blenderbot-400M-distill")
20
+
21
+ def predict(input, history=[]):
22
+ # tokenize the new input sentence
23
+ new_user_input_ids = tokenizer.encode(input + tokenizer.eos_token, return_tensors='pt')
24
+
25
+ # append the new user input tokens to the chat history
26
+ bot_input_ids = torch.cat([torch.LongTensor(history), new_user_input_ids], dim=-1)
27
+
28
+ # generate a response
29
+ history = model.generate(bot_input_ids, max_length=1000, pad_token_id=tokenizer.eos_token_id).tolist()
30
+
31
+ # convert the tokens to text, and then split the responses into lines
32
+ response = tokenizer.decode(history[0]).replace("<|endoftext|>", "\n")
33
+
34
+ return response, history
35
+
36
+ gr.Interface(
37
+ fn = predict,
38
+ inputs = ["textbox","state"],
39
+ outputs = ["chatbot","state"],
40
+ theme ="grass",
41
+ title = title,
42
+ description = description,
43
+ article = article
44
+ ).launch(enable_queue=True)
img/cover.png ADDED
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ transformers
2
+ torch