tinewto commited on
Commit
9a4b19a
1 Parent(s): e28ac63

Upload app.py

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