Curious-X commited on
Commit
91e5f94
1 Parent(s): bb8c3f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -1
app.py CHANGED
@@ -1,5 +1,27 @@
1
  import gradio as gr
 
 
 
2
 
3
- demo = gr.Interface.load("models/facebook/blenderbot-400M-distill")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  demo.launch()
 
1
  import gradio as gr
2
+ from transformers import AutoTokenizer, TFBlenderbotForConditionalGeneration
3
+ import tensorflow as tf
4
+ from transformers import pipeline, Conversation
5
 
6
+ tokenizer = AutoTokenizer.from_pretrained("facebook/blenderbot-400M-distill")
7
+ model = TFBlenderbotForConditionalGeneration.from_pretrained("facebook/blenderbot-400M-distill")
8
+
9
+ chatbot = pipeline(task="conversational",model=model,tokenizer=tokenizer)
10
+
11
+ def chatBotPred(message,history):
12
+ if len(history)>0:
13
+ past_user_inputs= [chat[0] for chat in history]
14
+ generated_responses= [chat[1] for chat in history]
15
+ else:
16
+ past_user_inputs= None
17
+ generated_responses= None
18
+
19
+ conversation = Conversation(text=message,
20
+ past_user_inputs=past_user_inputs,
21
+ generated_responses=generated_responses)
22
+ conversation = chatbot(conversation)
23
+ return conversation.generated_responses[-1]
24
+
25
+ demo = gr.ChatInterface(chatBotPred)
26
 
27
  demo.launch()