Spaces:
Running
Running
Commit
•
e2e0f97
1
Parent(s):
ae6a409
Update app.py
Browse files
app.py
CHANGED
@@ -10,24 +10,27 @@ def process_pdf(uploaded_file, qa_model, tokenizer):
|
|
10 |
file_contents = uploaded_file.read()
|
11 |
|
12 |
# Process the PDF file
|
13 |
-
doc = fitz.open(
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
31 |
|
32 |
# Main function
|
33 |
def main():
|
|
|
10 |
file_contents = uploaded_file.read()
|
11 |
|
12 |
# Process the PDF file
|
13 |
+
doc = fitz.open(file_contents, filetype="pdf")
|
14 |
+
if doc is not None:
|
15 |
+
text = ""
|
16 |
+
for page in doc:
|
17 |
+
text += page.get_text()
|
18 |
+
|
19 |
+
# Tokenize the text
|
20 |
+
inputs = tokenizer(text, return_tensors="pt", max_length=512, truncation=True)
|
21 |
+
|
22 |
+
# Perform question answering
|
23 |
+
outputs = qa_model(**inputs)
|
24 |
+
start_scores = outputs.start_logits
|
25 |
+
end_scores = outputs.end_logits
|
26 |
+
|
27 |
+
# Display the generated questions and answers
|
28 |
+
for i, (start, end) in enumerate(zip(start_scores, end_scores)):
|
29 |
+
answer = tokenizer.decode(inputs["input_ids"][i][start.argmax():end.argmax()+1])
|
30 |
+
st.write("Answer:", answer)
|
31 |
+
st.write("---")
|
32 |
+
else:
|
33 |
+
st.error("Error occurred while opening the PDF file.")
|
34 |
|
35 |
# Main function
|
36 |
def main():
|