sight_chat / app.py
fmegahed's picture
main app files
cd68afd verified
raw
history blame
2.63 kB
import streamlit as st
from query_graph import query_graph
# Sidebar configuration
st.sidebar.title("About")
st.sidebar.markdown("**Authors:** [The SIGHT Project Team](https://sites.miamioh.edu/sight/)")
st.sidebar.markdown("**Version:** V. 0.0.1")
st.sidebar.markdown("**Date:** July 24, 2025")
st.sidebar.markdown("**Model:** gpt4o")
st.sidebar.markdown("---")
st.sidebar.markdown(
"**Funding:** SIGHT is funded by [OHBWC WSIC](https://info.bwc.ohio.gov/for-employers/safety-services/workplace-safety-innovation-center/wsic-overview)"
)
# References toggle in sidebar
st.sidebar.markdown("---")
show_refs = st.sidebar.checkbox("Show references")
# Main interface
st.set_page_config(page_title="Miami University's SIGHT Chatbot")
st.title("Chat with SIGHT")
st.write("Ask questions about machine safeguarding, LOTO, and hazard prevention based on OSHA/CFR's corpus.")
# Example questions toggled in main window
with st.expander("Example Questions", expanded=False):
st.markdown(
"- What are general machine guarding requirements? \n"
"- How do I perform lockout/tagout? \n"
"- Summarize the definition of machine guarding from 29 CFR 1910.211"
)
# Initialize chat history
if 'history' not in st.session_state:
st.session_state.history = []
# User input
query = st.text_input("Your question:")
if st.button("Send") and query:
answer, sources = query_graph(query)
st.session_state.history.append({
'query': query,
'answer': answer,
'sources': sources
})
# Display chat history
for i, entry in enumerate(st.session_state.history):
st.markdown(f"**You:** {entry['query']}")
st.markdown(f"**Assistant:** {entry['answer']}")
# Explanations expander
with st.expander("Sources used", expanded=False):
for src in entry['sources']:
st.markdown(f"- {src}")
# Optionally show references list
if show_refs:
refs = [
"29 CFR 1910.211", "29 CFR 1910.212", "29 CFR 1910.213", "29 CFR 1910.215",
"OSHA 3170", "OSHA 3120", "NIOSH WP Solutions 2011-156", "NIOSH Robotics (2024)"
]
for r in refs:
st.sidebar.markdown(f"- {r}")
# Footer
st.markdown("---")
st.markdown(
"**Disclaimer:** *Powered by a Graph RAG to reduce hallucinations; please verify as it can still make mistakes.*"
)
st.markdown(
"**Funding:** *We are thankful for [Ohio BWC/WSIC](https://info.bwc.ohio.gov/for-employers/safety-services/workplace-safety-innovation-center/wsic-overview)'s funding that made this chat bot possible.*"
)