Kaysarulanas commited on
Commit
44bf281
1 Parent(s): 46a9591

Update app.py

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