Spaces:
Paused
Paused
File size: 3,172 Bytes
cd68afd 01c0ebb cd68afd 01c0ebb cd68afd 01c0ebb cd68afd 01c0ebb cd68afd 01c0ebb cd68afd 01c0ebb cd68afd |
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
import streamlit as st
from query_graph import query_graph
# Helper for <details>
def format_citations_html(chunks):
html = []
for idx, (hdr, sc, txt, citation) in enumerate(chunks, start=1):
preamble = (
f"<p style='font-size:0.9em;'><strong>Preamble:</strong> "
f"The text in the following detail is reproduced from [{citation}]. "
f"It had a cosine similarity of {sc:.2f} with the user question, "
f"and it ranked {idx} among the text chunks in our graph database.</p>"
)
body = txt.replace("\n", "<br>")
html.append(
f"<details>"
f"<summary>{hdr} (cosine similarity: {sc:.2f})</summary>"
f"<div style='font-size:0.9em; margin-top:0.5em;'>"
f"<strong>Preamble:</strong> The text below is reproduced from {citation}. "
f"</div>"
f"<div style='font-size:0.7em; margin-left:1em; margin-top:0.5em;'>{body}</div>"
f"</details><br><br>"
)
return "<br>".join(html)
# 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.2")
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)"
)
# 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, chunks = query_graph(query)
st.session_state.history.append({
'query': query,
'answer': answer,
'sources': sources,
'chunks': chunks
})
# Display chat history
for entry in st.session_state.history[::-1]:
st.markdown(f"**You:** {entry['query']}")
st.markdown(f"**Assistant:** {entry['answer']}")
st.markdown(format_citations_html(entry['chunks']), unsafe_allow_html=True)
# 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.*"
) |