Spaces:
Sleeping
Sleeping
Zack
commited on
Commit
·
45656bc
1
Parent(s):
a2a1490
Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
def load_file():
|
5 |
+
"""Load text from file"""
|
6 |
+
uploaded_file = st.file_uploader("Upload Files",type=['txt'])
|
7 |
+
|
8 |
+
if uploaded_file is not None:
|
9 |
+
if uploaded_file.type == "text/plain":
|
10 |
+
raw_text = str(uploaded_file.read(),"utf-8")
|
11 |
+
return raw_text
|
12 |
+
|
13 |
+
|
14 |
+
if __name__ == "__main__":
|
15 |
+
|
16 |
+
# App title and description
|
17 |
+
st.title("Answering questions from text")
|
18 |
+
st.write("Upload text, pose questions, get answers")
|
19 |
+
|
20 |
+
# Load file
|
21 |
+
raw_text = load_file()
|
22 |
+
if raw_text != None and raw_text != '':
|
23 |
+
|
24 |
+
# Display text
|
25 |
+
with st.expander("See text"):
|
26 |
+
st.write(raw_text)
|
27 |
+
|
28 |
+
# Perform question answering
|
29 |
+
question_answerer = pipeline('question-answering')
|
30 |
+
|
31 |
+
answer = ''
|
32 |
+
question = st.text_input('Ask a question')
|
33 |
+
|
34 |
+
if question != '' and raw_text != '':
|
35 |
+
answer = question_answerer({
|
36 |
+
'question': question,
|
37 |
+
'context': raw_text
|
38 |
+
})
|
39 |
+
|
40 |
+
st.write(answer)
|