Spaces:
Runtime error
Runtime error
File size: 1,726 Bytes
e2123b4 e3519cb e2123b4 e3519cb e2123b4 e3519cb e2123b4 e3519cb e2123b4 e3519cb c460739 e2123b4 e3519cb a404def 2019002 12d7fe0 e3519cb e2123b4 e3519cb |
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
import itertools
import gradio as gr
import requests
import os
def respond(message, history):
if len(message.strip()) == 0:
return "ERROR the question should not be empty"
local_token = os.environ['API_TOKEN']
local_endpoint = os.environ['API_ENDPOINT']
# Add your API token to the headers
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {local_token}'
}
prompt = list(itertools.chain.from_iterable(history))
prompt.append(message)
q = {"inputs": [prompt]}
try:
response = requests.post(local_endpoint, json=q, headers=headers, timeout=100)
response_data = response.json(
)["predictions"]
except:
response_data = "ERROR status_code:" + \
str(response.status_code) + " response:" + response.text
#print(response.json())
return response_data
demo = gr.ChatInterface(
respond,
chatbot=gr.Chatbot(height=400),
textbox=gr.Textbox(placeholder="Ask me a question",
container=False, scale=7),
title="Databricks LLM RAG demo - Chat with llama2 Databricks model serving endpoint",
description="This chatbot is a demo example for the dbdemos llm chatbot. <br>This content is provided as a LLM RAG educational example, without support. It is using llama2, can hallucinate and should not be used as production content.<br>Please review our dbdemos license and terms for more details.",
examples=[["How can I start a Databricks cluster?"], ["What is a Databricks Cluster Policy?"]],
cache_examples=False,
theme="soft",
retry_btn=None,
undo_btn=None,
clear_btn="Clear"
)
if __name__ == "__main__":
demo.launch()
|