ChatRobo3.0 / app.py
RamV's picture
Update app.py
8788c2d
raw
history blame contribute delete
916 Bytes
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()