You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromPILimportImageimportgoogle.generativeaiasgenaigenai.configure(api_key="HERE")
model=genai.GenerativeModel('models/gemini-1.5-flash')
prompt="""Perform OCR on the given image. Please strip the header and return questions in JSON format.There are 2 formats of question and answer:1) question and written answer. Generally, it has "ตอบ" following with the text which could be in iterable format with numbers2) multiple choice where the answer is in boldface. Here, we want to return the output in the JSON format:{ text: non relevant text questions: [{question, [choices], answer}, ...] (for multiple choice format) or questions: [{quetsion, answer in plain text}] (for question and answer format)}Your answer:"""page_ranges= [
(74, 81, "ธรรมศึกษาชั้นตรี ระดับประถมศึกษา"),
(81, 88, "ธรรมศึกษาชั้นตรี ระดับประถมศึกษา"),
(88, 95, "ธรรมศึกษาชั้นตรีระดับประถมศึกษา"),
]
extracted_questions= []
forpage_rangeintqdm(page_ranges):
start, end, topic=page_rangeforiinrange(start, end):
image=Image.open(f"Dhamma_Test/page-{i}.png")
response=model.generate_content([prompt, image])
extracted_questions.append({
"page": i+1,
"topic": topic,
"questions": response.text
})