Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,25 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
|
| 5 |
-
st.title("🤖 AI Chatbot - Hugging Face")
|
| 6 |
|
| 7 |
-
# Initialize chatbot model
|
| 8 |
@st.cache_resource
|
| 9 |
-
def
|
| 10 |
-
return pipeline("
|
| 11 |
|
| 12 |
-
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
|
|
|
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
st.title("❓ AI Question Answering Bot")
|
|
|
|
| 5 |
|
|
|
|
| 6 |
@st.cache_resource
|
| 7 |
+
def load_qa():
|
| 8 |
+
return pipeline("question-answering", model="deepset/roberta-base-squad2")
|
| 9 |
|
| 10 |
+
qa = load_qa()
|
| 11 |
|
| 12 |
+
# Set a static context or let user provide it
|
| 13 |
+
context = st.text_area("📄 Paste your reference text (context):",
|
| 14 |
+
"The QA QC Electrical Inspector ensures the quality of installations, performs inspection and testing, and checks documentation in power and oil & gas projects.")
|
| 15 |
|
| 16 |
+
question = st.text_input("❓ Your question:")
|
| 17 |
+
|
| 18 |
+
if question:
|
| 19 |
+
try:
|
| 20 |
+
with st.spinner("Thinking..."):
|
| 21 |
+
answer = qa(question=question, context=context)
|
| 22 |
+
st.markdown(f"**Answer:** {answer['answer']}")
|
| 23 |
+
except Exception as e:
|
| 24 |
+
st.error("Something went wrong.")
|
| 25 |
+
st.exception(e)
|