import cv2 import easyocr import gradio as gr from main import predict_mcq reader = easyocr.Reader(['th','en']) def ocr_with_easy(image): #gray_scale_image=get_grayscale(img) #thresholding(gray_scale_image) cv2.imwrite('image.png',image) image=cv2.imread('image.png') bounds = reader.readtext(image,paragraph="False",detail = 0) bounds = ''.join(bounds) return bounds def put_in_single_list(data): result=[] final_result=[] for i in data: result.append(i.get("question_statement")) result.append(i.get("answer")) result.append(i.get("options")) final_result.append(result) return final_result def MCQGenerator(image): I_text=ocr_with_easy(image) text={ "input_text":I_text } Mcqs=predict_mcq(text) data=Mcqs.get('questions') print(data) if data is not None: #final_result=put_in_single_list(data) statement="" answer="" options="" for mcq in data: statement+=mcq.get('question_statement')+',' answer+=mcq.get('answer')+',' options+=mcq.get('options')[0]+','+mcq.get('options')[1]+','+mcq.get('options')[2]+',' return statement,answer,options else: return "Null","Null","Null" iface=gr.Interface(fn=MCQGenerator,inputs='image',outputs=[gr.components.Textbox(label="Question"),gr.components.Textbox(label="Answer"),gr.components.Textbox(label="Options")], examples=[['demo.PNG']]) iface.launch(debug=True)