File size: 916 Bytes
36b41f7
e6612ee
36b41f7
e6612ee
 
11bb600
e6612ee
11bb600
e6612ee
11bb600
 
 
e6612ee
11bb600
e6612ee
8788c2d
e6612ee
11bb600
36b41f7
e6612ee
 
 
36b41f7
 
b984ecb
c593c1e
 
 
 
b984ecb
e6612ee
171e224
 
95701e0
6846058
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import gradio as gr
import requests

def huggingface_chat_history(input, history=[]):
    # create payload dictionary
    payload = {
        "inputs": input,
        "parameters": {
            "history": history
        }
    }

    # make request to Hugging Face model API
    response = requests.post(
        "https://api-inference.huggingface.co/models/microsoft/DialoGPT-medium", 
        headers={"Authorization": "ChatGPT"}, 
        json=payload
    )

    # extract chatbot response from API response
    chat_response = response.json()[0]['generated_text']
    history.append([input, chat_response])
    return chat_response

conversation_prompt = "Welcome to ChatRobo, kindly type in your enquiries: "
block = gr.Interface(
    fn=huggingface_chat_history, 
    inputs=[gr.inputs.Textbox(placeholder=conversation_prompt)], 
    outputs=[gr.outputs.Textbox(label="ChatRobo Output")]
)

block.launch()