Spaces:
Running
Running
File size: 3,449 Bytes
0764ea9 |
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 56 57 58 59 60 61 62 63 64 65 |
import streamlit as st
from streamlit_chat import message
import requests
import pandas as pd
import plotly.express as px
st.set_page_config(layout="wide")
API_URL = "http://127.0.0.1:5000/api"
headers = {"Content-Type": "application/json"}
def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)
return response.json()
def generate_response(user,prompt):
output = query({"namespace":"virtualEngineer","version":1,"messages":[{"role":user, "content": prompt}]})
return output
#Creating the chatbot interface
st.title("Engineering Expert")
st.caption("This is a proof of concept to demonstrate our Generative Enterprise Knowledge Navigator Cognitive Architecture. This demo contains 170 PDFs from a leading elevator manufacturer and maintenance company. This volume of information represents the maintenance manuals and product documentation for the doors for one generation of their lifts. The solution to this point provided search results, our challenge was to take this knowledge and provide actionable insights first accompanied by the file and page numbers that the information was sourced from.")
col1, col2 = st.columns(2)
# Storing the chat
if 'generated' not in st.session_state:
st.session_state['generated'] = []
if 'past' not in st.session_state:
st.session_state['past'] = []
with col1:
with st.form(key='my_form'):
User = st.text_input("Step 1 Set Engeineer Name","", key="user")
input_text = st.text_input("Step 2 How can I help today?","", key="input")
submit_button = st.form_submit_button(label='Submit')
if submit_button:
output = generate_response(User,input_text)
# store the output
st.session_state.past.append(input_text)
st.session_state.generated.append(output['choices'][0]['message']['content'])
df = pd.DataFrame(output["sources"])
fig = px.scatter(df, y="Score",color="Source", hover_data=['Insight'])
fig.update_layout(showlegend=False)
# Layout the columns
st.subheader("Response Data")
st.caption(f"Overall Answer Confidence: {output['accuracy']}%")
st.caption(f"Time Taken: {round(output['timeTaken'],1)} Seconds")
st.caption(f"Cognitive Cache Hit: {output['cacheHit']}")
st.caption('The below chart shows the distribution of knowledge in the knowledge store. This is used to supply expert information to answer your specific question. We request the top 100 results to speed up this demo, but analysing the knowledge store is an important part of maintaining high quality knowledge base which is key to high alignment, minimising hallucinations and ensuring safety.')
st.plotly_chart(fig, theme=None, use_container_width=True)
st.caption('Sources:')
st.caption('This table represents the books and their page numbers that were used to create the expert answer')
st.table(df.loc[:, ['Score', 'Source', 'startpage']].head(5))
if st.session_state['generated']:
for i in range(len(st.session_state['generated'])-1, -1, -1):
with col2:
message(st.session_state["generated"][i], key=str(i),avatar_style="identicon",seed="Socks")
message(st.session_state['past'][i], is_user=True, key=str(i) + '_user',avatar_style="identicon",seed="Mittens")
|