File size: 993 Bytes
2a8f14f
 
 
 
 
3139b67
2a8f14f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3139b67
 
2a8f14f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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)
    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')
  final_result=put_in_single_list(data)
  return final_result

iface=gr.Interface(fn=MCQGenerator,inputs="image",outputs=[gr.components.Textbox(label="MCQS")],
                  examples=[['demo.PNG']])
iface.launch(debug=True)