Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the question answering pipeline
|
5 |
+
question_answerer = pipeline("question-answering", model='distilbert-base-cased-distilled-squad')
|
6 |
+
|
7 |
+
# Streamlit app
|
8 |
+
def main():
|
9 |
+
st.title("Question Answering Chat App")
|
10 |
+
|
11 |
+
# Text input for context
|
12 |
+
context = st.text_area("Enter the context:", """
|
13 |
+
Extractive Question Answering is the task of extracting an answer from a text given a question.
|
14 |
+
""")
|
15 |
+
|
16 |
+
# Text input for question
|
17 |
+
question = st.text_input("Enter your question:")
|
18 |
+
|
19 |
+
# Answer the question
|
20 |
+
if st.button("Get Answer"):
|
21 |
+
result = question_answerer(question=question, context=context)
|
22 |
+
st.subheader("Answer:")
|
23 |
+
st.write(result['answer'])
|
24 |
+
st.subheader("Details:")
|
25 |
+
st.write(f"Score: {round(result['score'], 4)}")
|
26 |
+
st.write(f"Start: {result['start']}")
|
27 |
+
st.write(f"End: {result['end']}")
|
28 |
+
|
29 |
+
if __name__ == "__main__":
|
30 |
+
main()
|