Funbi commited on
Commit
4fbef82
1 Parent(s): 893807e

Add application file

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
13
+ def chat(message):
14
+ past_user=["what is your name?"]
15
+ generated=["I am Sade, Funbi's AI chatbot"]
16
+ message = message.lower()
17
+ if message.startswith("what is your name"):
18
+ 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"])
19
+ elif "your name" in message:
20
+ 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"])
21
+ elif "who are you" in message:
22
+ 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"])
23
+ else:
24
+ response = query({"inputs": {"past_user_inputs":past_user,"generated_responses":generated,"text":message},})
25
+ response = response['generated_text']
26
+ past_user.append(message)
27
+ generated.append(response)
28
+ #history.append((message, response))
29
+ return response
30
+
31
+ demo = gr.Interface(
32
+ chat,
33
+ inputs="text",
34
+ outputs="text",
35
+ title="Chatbot",
36
+ 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",
37
+
38
+ )
39
+ demo.launch()