Но когда я пытаюсь добавить удаленные вопросы в файл, который я использовал для тонкой настройки вопрос весь в одной строке, а не в переносах строк.
Код: Выделить всё
import pytesseract
import cv2
import pypdf
import re
reader = pypdf.PdfReader(r'C:\Users\kenco\OneDrive\Desktop\AI Stuff\llms\exam_emulation\papers\example_pdf.pdf')
questions = []
found = False
question = """"""
for page in reader.pages:
text = page.extract_text()
text = re.sub(r'[^\x20-\x7E]', '', text)
lines = text.splitlines()
start = 0
for line in text.splitlines():
question += line + '\n'
if 'Q u e s t i o n' in line:
questions.append(question)
question = """"""
with open('extracted_text.txt', 'w') as file:
for question in questions:
file.write(question)
file.write('\n')
Код: Выделить всё
(50marks)(a) AnewLeisureCentreiso peninginyourareaandanumberofpositions(jobs)willhavetobefilledwithinthecentre.NamethreepositionsthatwillhavetobefilledintheLeisureCentreanddescribeoned u t y o f e a c h p o s i t i o n . (14marks)Position Duty1. 2. 3. (b) (12marks)ListthreeActiveLeisureactivitiesthatattracttouriststoFrance.1.________________________________________________________________________2._______________________________
Код: Выделить всё
question.replace('\uf0fc', '\n')
Подробнее здесь: https://stackoverflow.com/questions/793 ... hin-a-list
Мобильная версия