Habieb143 commited on
Commit
a626dd6
·
verified ·
1 Parent(s): 49ea6d4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -11
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import streamlit as st
 
2
  from transformers import pipeline, AutoTokenizer, AutoModelForQuestionAnswering
3
 
4
  @st.cache(allow_output_mutation=True)
@@ -11,15 +12,34 @@ def load_qa_model():
11
 
12
  qa = load_qa_model()
13
 
14
- st.title("Ask Questions about your Text")
15
- sentence = st.text_area('Please paste your article :', height=30)
16
- question = st.text_input("Questions from this article?")
17
- button = st.button("Get me Answers")
18
- max_seq_length = st.sidebar.slider('Select max sequence length', 50, 500, step=10, value=150)
19
- do_sample = st.sidebar.checkbox("Do sample", value=False)
 
 
 
 
 
20
 
21
- with st.spinner("Discovering Answers.."):
22
- if button and sentence:
23
- answers = qa(question=question, context=sentence)
24
- st.write("Answer:", answers['answer'])
25
- st.write("Score:", answers['score'])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import pandas as pd
3
  from transformers import pipeline, AutoTokenizer, AutoModelForQuestionAnswering
4
 
5
  @st.cache(allow_output_mutation=True)
 
12
 
13
  qa = load_qa_model()
14
 
15
+ def process_batch(data):
16
+ results = []
17
+ for index, row in data.iterrows():
18
+ answer = qa(question=row['Question'], context=row['Article'])
19
+ results.append({
20
+ 'Question': row['Question'],
21
+ 'Article': row['Article'],
22
+ 'Answer': answer['answer'],
23
+ 'Score': answer['score']
24
+ })
25
+ return results
26
 
27
+ st.title("Batch Question Answering App")
28
+
29
+ uploaded_file = st.file_uploader("Upload a CSV file", type="csv")
30
+
31
+ if uploaded_file is not None:
32
+ data = pd.read_csv(uploaded_file)
33
+ st.write("Uploaded file:")
34
+ st.write(data)
35
+
36
+ if st.button("Process Batch"):
37
+ with st.spinner("Processing Batch..."):
38
+ results = process_batch(data)
39
+ st.write("Batch Processing Results:")
40
+ for result in results:
41
+ st.write("Question:", result['Question'])
42
+ st.write("Article:", result['Article'])
43
+ st.write("Answer:", result['Answer'])
44
+ st.write("Score:", result['Score'])
45
+ st.write("------")