File size: 855 Bytes
b38fe5a
 
 
06fc207
b38fe5a
 
06fc207
 
b38fe5a
06fc207
b38fe5a
06fc207
 
 
b38fe5a
06fc207
 
 
 
 
 
 
 
 
 
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
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()

# Set a static context or let user provide it
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)