Funbi commited on
Commit
9fe2179
1 Parent(s): a70815f

Add application file

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import random
2
+ import gradio as gr
3
+ import requests
4
+
5
+ API_URL = "https://api-inference.huggingface.co/models/facebook/blenderbot-3B"
6
+ headers = {"Authorization": "Bearer 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"}
7
+
8
+ def query(payload):
9
+ response = requests.post(API_URL, headers=headers, json=payload)
10
+ return response.json()
11
+
12
+ #output = query({
13
+ #"inputs": {
14
+ #"past_user_inputs": ["Which movie is the best ?"],
15
+ # "generated_responses": ["It's Die Hard for sure."],
16
+ # "text": "Can you explain why ?"
17
+ #},
18
+ #})
19
+ def chat(message, history):
20
+ past_user=["what is your name?"]
21
+ generated=["I am Sade, Funbi's AI chatbot"]
22
+ history = history or []
23
+ message = message.lower()
24
+ if message.startswith("what is your name"):
25
+ response = random.choice(["I am Sade an AI chatbot made by Funbi,how are you?","Sade, an AI chatbot made by Funbi, feel free to ask me anything"])
26
+ elif "your name" in message:
27
+ response = random.choice(["I am Sade an AI chatbot made by Funbi,how are you?","Sade, an AI chatbot made by Funbi, feel free to ask me anything"])
28
+ elif "who are you" in message:
29
+ response = random.choice(["I am Sade an AI chatbot made by Funbi,how are you?","Sade, an AI chatbot made by Funbi, feel free to ask me anything"])
30
+ else:
31
+ response = query({"inputs": {"past_user_inputs":past_user,"generated_responses":generated,"text":message},})
32
+ response = response['generated_text']
33
+ past_user.append(message)
34
+ generated.append(response)
35
+ history.append((message, response))
36
+ return history, history
37
+
38
+ chatbot = gr.Chatbot().style(color_map=("green", "pink"))
39
+ demo = gr.Interface(
40
+ chat,
41
+ ["text", "state"],
42
+ [chatbot, "state"],
43
+ allow_flagging="never",title="Chatbot",
44
+ description="This is chatbot made by using a pre-train model by Facebook called blender and I then primed it with a little extra information",
45
+
46
+ )
47
+ demo.launch()