Spaces:
Sleeping
Sleeping
Yereque
commited on
Commit
·
badb581
1
Parent(s):
f7b4690
first commit
Browse files
app.py
CHANGED
@@ -1,47 +1,49 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import pipeline
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
# Title and Description
|
7 |
-
st.title("Sentiment Analysis Web App")
|
8 |
st.write("""
|
9 |
### Powered by Hugging Face and Streamlit
|
10 |
-
This app uses a pre-trained NLP model from Hugging Face to
|
11 |
-
Try entering a
|
12 |
""")
|
13 |
|
14 |
-
#
|
15 |
@st.cache_resource
|
16 |
def load_model():
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
else:
|
38 |
-
st.warning("Please enter
|
39 |
|
40 |
# Sidebar with About Information
|
41 |
st.sidebar.title("About")
|
42 |
st.sidebar.info("""
|
43 |
This app demonstrates the use of Hugging Face's NLP models with Streamlit.
|
44 |
-
It uses the
|
45 |
""")
|
46 |
|
47 |
-
print('after')
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import AutoTokenizer, AutoModelForQuestionAnswering, pipeline
|
3 |
|
4 |
+
st.title("Question Answering Web App")
|
|
|
|
|
|
|
5 |
st.write("""
|
6 |
### Powered by Hugging Face and Streamlit
|
7 |
+
This app uses a pre-trained NLP model from Hugging Face to answer questions based on the text you provide.
|
8 |
+
Try entering a context and a question to get an answer!
|
9 |
""")
|
10 |
|
11 |
+
# Load the tokenizer and model
|
12 |
@st.cache_resource
|
13 |
def load_model():
|
14 |
+
tokenizer = AutoTokenizer.from_pretrained("Rakib/roberta-base-on-cuad")
|
15 |
+
model = AutoModelForQuestionAnswering.from_pretrained("Rakib/roberta-base-on-cuad")
|
16 |
+
return tokenizer, model
|
17 |
+
|
18 |
+
tokenizer, model = load_model()
|
19 |
+
|
20 |
+
# Define the question-answering pipeline
|
21 |
+
@st.cache_resource
|
22 |
+
def get_qa_pipeline():
|
23 |
+
return pipeline("question-answering", model=model, tokenizer=tokenizer)
|
24 |
+
|
25 |
+
qa_pipeline = get_qa_pipeline()
|
26 |
+
|
27 |
+
# UI input for context and question
|
28 |
+
context = st.text_area("Enter the context:", "Type the paragraph here where the answer will be extracted.")
|
29 |
+
question = st.text_input("Enter the question:", "What is being asked here?")
|
30 |
+
|
31 |
+
# Button to perform question answering
|
32 |
+
if st.button("Answer Question"):
|
33 |
+
if context and question:
|
34 |
+
result = qa_pipeline(question=question, context=context)
|
35 |
+
answer = result['answer']
|
36 |
+
|
37 |
+
# Display the result
|
38 |
+
st.subheader("Answer")
|
39 |
+
st.write(f"**Answer:** {answer}")
|
40 |
else:
|
41 |
+
st.warning("Please enter both context and question!")
|
42 |
|
43 |
# Sidebar with About Information
|
44 |
st.sidebar.title("About")
|
45 |
st.sidebar.info("""
|
46 |
This app demonstrates the use of Hugging Face's NLP models with Streamlit.
|
47 |
+
It uses the `Rakib/roberta-base-on-cuad` model for question answering tasks.
|
48 |
""")
|
49 |
|
|