Canstralian commited on
Commit
e72331f
·
verified ·
1 Parent(s): ce12cc5

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ # Title and Description
5
+ st.title("WhiteRabbitNEO Q&A App")
6
+ st.write("Ask any question, and WhiteRabbitNEO will provide an answer.")
7
+
8
+ # Initialize the model pipeline
9
+ @st.cache_resource
10
+ def load_model():
11
+ try:
12
+ return pipeline("question-answering", model="WhiteRabbitNEO")
13
+ except Exception as e:
14
+ st.error(f"Failed to load model: {e}")
15
+ return None
16
+
17
+ qa_pipeline = load_model()
18
+
19
+ # Input Section
20
+ if qa_pipeline:
21
+ question = st.text_input("Enter your question:")
22
+ context = st.text_area("Provide some context for the question:")
23
+
24
+ # Output Section
25
+ if st.button("Get Answer"):
26
+ if question and context:
27
+ with st.spinner("Thinking..."):
28
+ try:
29
+ result = qa_pipeline(question=question, context=context)
30
+ st.success("Answer:")
31
+ st.write(result["answer"])
32
+ st.write(f"Confidence: {result['score']:.2f}")
33
+ except Exception as e:
34
+ st.error(f"Error generating answer: {e}")
35
+ else:
36
+ st.warning("Please provide both a question and context.")
37
+ else:
38
+ st.warning("The model pipeline couldn't be loaded. Please check your setup.")