Spaces:
Sleeping
Sleeping
File size: 1,527 Bytes
df36d99 |
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
import os
import json
import pandas as pd
import PyPDF2
import traceback
def read_flie(file):
if file.name.endswith('.pdf'):
try :
pdf_content = PyPDF2.PdfFileReader(file)
text = ''
for page in pdf_content.pages:
text+=page
return text
except Exception as e :
raise Exception( 'error in reading the file >> Please try reuploading')
elif file.name.endswith('.txt'):
return file.read().decode('utf-8')
else :
raise Exception(
'Not File desired format : only PDF and txt files are supported '
)
def get_table_data(quiz_str):
try :
quiz_dict = json.loads(quiz_str)
table = []
for key,value in quiz_dict.items():
print(key," | ",value)
ques = value['question']
options = ' | '.join(
[
f"{option} : {options}"
for option, options in value['options'].items()
]
)
correct = value['correct']
table.append({'ques':ques,'options' : options, 'correct' : correct})
return table
except Exception as e :
# traceback.print(e)
return False
|