q_and_a_bot / main.py
esiol's picture
Update main.py
55e3619
raw
history blame contribute delete
939 Bytes
import os
import requests
import gradio as gr
def get_the_answer(message, history):
endpoint = 'eo_rfp_rag'
try:
token = os.environ['DATABRICKS_TOKEN']
host = os.environ['DATABRICKS_HOST']
headers = {"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
print(f"{host}serving-endpoints/{endpoint}/invocations")
answer = requests.post(f"{host}serving-endpoints/{endpoint}/invocations",
json={"dataframe_split": {"data":[message]}},
headers=headers).json()
output = answer['predictions'][0]['answer']
except KeyError as e:
return str(answer['message'])
except Exception as e:
return str(e)
print(answer.keys())
return answer['predictions'][0]['answer']
demo = gr.ChatInterface(get_the_answer)
demo.launch(auth=[("User1", os.environ['PASS']), ("User2", os.environ['PASS'])])