Commit
·
e4ecc70
1
Parent(s):
4611c59
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,7 +25,9 @@ def generate_question_answer_pairs(input_file):
|
|
| 25 |
pdf_text = extract_text_from_pdf(input_file)
|
| 26 |
|
| 27 |
sentences = re.split(r'(?<=[.!?])', pdf_text)
|
| 28 |
-
|
|
|
|
|
|
|
| 29 |
|
| 30 |
for sentence in sentences:
|
| 31 |
if sentence.strip():
|
|
@@ -33,8 +35,14 @@ def generate_question_answer_pairs(input_file):
|
|
| 33 |
"inputs": sentence,
|
| 34 |
})
|
| 35 |
outputs.append(output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
return
|
| 38 |
|
| 39 |
title = "Question-Answer Pairs Generation"
|
| 40 |
input_file = gr.File(label="Upload a PDF file")
|
|
|
|
| 25 |
pdf_text = extract_text_from_pdf(input_file)
|
| 26 |
|
| 27 |
sentences = re.split(r'(?<=[.!?])', pdf_text)
|
| 28 |
+
|
| 29 |
+
outputs = []
|
| 30 |
+
result = ''
|
| 31 |
|
| 32 |
for sentence in sentences:
|
| 33 |
if sentence.strip():
|
|
|
|
| 35 |
"inputs": sentence,
|
| 36 |
})
|
| 37 |
outputs.append(output)
|
| 38 |
+
|
| 39 |
+
for i in outputs:
|
| 40 |
+
chunk = outputs[i][0]['generated_text']
|
| 41 |
+
question_part = re.search(r'^(.*?\?)',chunk).group(1).strip()
|
| 42 |
+
answer_part = re.search(r'\?(.*)', chunk).group(1).strip()
|
| 43 |
+
result += f"Question: {question_part}\nAnswer: {answer_part}\n\n"
|
| 44 |
|
| 45 |
+
return result
|
| 46 |
|
| 47 |
title = "Question-Answer Pairs Generation"
|
| 48 |
input_file = gr.File(label="Upload a PDF file")
|