AIQuizGenerator / fileCreator.py
Rehman1603's picture
Update fileCreator.py
2497fb1 verified
from docx import Document
from docx.shared import Inches
import random
def get_Options(MCQS ,no):
Options=MCQS.get("questions")[no].get('options')
answer=MCQS.get("questions")[no].get('answer')
return Options,answer
def get_MCQS_Statement(MCQS,i):
text=MCQS.get("questions")[i].get("question_statement")
return text
def get_sq(sq_result,i):
text=sq_result.get('questions')[i].get('Question')
return text
def get_Paragraph(pararesult):
text=pararesult.get('Question')
return text
def get_Paragraph_Question(pararesult):
text=pararesult.get("Paraphrased Questions")
return text
def GenerateMCQSDocument(MCQS):
document = Document()
document.add_heading('Quiz', 0)
table = document.add_table(rows=1, cols=5)
hdr_cells = table.rows[0].cells
hdr_cells[0].text = 'Statement'
hdr_cells[1].text = 'A'
hdr_cells[2].text = 'B'
for i in range(0,3,1):
state=get_MCQS_Statement(MCQS,i)
print(state)
MCqs_Options,ans=get_Options(MCQS,i)
print(MCqs_Options)
print(ans)
row_cells = table.add_row().cells
row_cells[0].text = str(state)
row_cells[1].text = MCqs_Options[0]
row_cells[3].text = ans
document.add_page_break()
document.save('Document.docx')
def GenerateSQDocument(sq_result):
document = Document()
document.add_heading('Quiz', 0)
table = document.add_table(rows=1, cols=1)
hdr_cells = table.rows[0].cells
hdr_cells[0].text = 'Questions'
for i in range(0,3,1):
ques=get_sq(sq_result,i)
print(ques)
row_cells = table.add_row().cells
row_cells[0].text = str(ques)
document.add_page_break()
document.save('Document1.docx')
def GenerateParaphraseDocument(pararesult):
document = Document()
paragraph=get_Paragraph(pararesult)
Question=get_Paragraph_Question(pararesult)
document.add_heading('Quiz', 0)
document.add_paragraph(paragraph,style='Intense Quote')
table = document.add_table(rows=1, cols=1)
hdr_cells = table.rows[0].cells
hdr_cells[0].text = 'Questions'
for i in range(0,3,1):
row_cells = table.add_row().cells
row_cells[0].text = Question[i]
document.add_page_break()
document.save('Document2.docx')