|
|
import streamlit as st |
|
|
from transformers import pipeline |
|
|
|
|
|
st.title("β AI Question Answering Bot") |
|
|
|
|
|
@st.cache_resource |
|
|
def load_qa(): |
|
|
return pipeline("question-answering", model="deepset/roberta-base-squad2") |
|
|
|
|
|
qa = load_qa() |
|
|
|
|
|
|
|
|
context = st.text_area("π Paste your reference text (context):", |
|
|
"The QA QC Electrical Inspector ensures the quality of installations, performs inspection and testing, and checks documentation in power and oil & gas projects.") |
|
|
|
|
|
question = st.text_input("β Your question:") |
|
|
|
|
|
if question: |
|
|
try: |
|
|
with st.spinner("Thinking..."): |
|
|
answer = qa(question=question, context=context) |
|
|
st.markdown(f"**Answer:** {answer['answer']}") |
|
|
except Exception as e: |
|
|
st.error("Something went wrong.") |
|
|
st.exception(e) |
|
|
|