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 = "https://virtual-eng-expert-api-v1.greensea-b20be511.northeurope.azurecontainerapps.io/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("Problem: A major facilities engineering provider with over 40,000 field-based engineers and a large PDF-based knowledge repository of over 100,000 pages of documents faced significant challenges. The existing system used a metadata-driven search, which was highly manual to maintain and inefficient for engineers needing quick access to relevant information. This inefficiency led to delays in field operations and difficulties in maintaining up-to-date knowledge across the organization.") st.caption("Solution: To address this challenge, the engineering provider implemented a Virtual Engineering Assistant powered by Generative AI (GenAI). The solution involved developing an advanced information science strategy that leveraged a vector database and unique memory architectures to improve information retrieval and decision support.") 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 Engineer 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")