Funbi/Chat2
1
1import random2import gradio as gr3import requests4 5API_URL = "https://api-inference.huggingface.co/models/facebook/blenderbot-3B"6headers = {"Authorization": "Bearer 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"}7 8def query(payload):9 response = requests.post(API_URL, headers=headers, json=payload)10 return response.json()11 12 13def 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 response30 31demo = 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)39demo.launch()40 