CoolFace
Apppublic

Funbi/Chatbot

sourceHugging Faceupdated 4y agoView on Hugging Face
0likes
app.py48 linesDownload Raw Back to root
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#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#})19def 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, history37 38chatbot = gr.Chatbot().style(color_map=("green", "pink"))39demo = 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)47demo.launch()48