Spaces:
Runtime error
Runtime error
File size: 1,069 Bytes
0031bc0 ca9282a e44bedb 0031bc0 4d9924a 0031bc0 4d9924a 6806316 4d9924a 6806316 4d9924a 0031bc0 6806316 | 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 | import json
from langchain_community.document_loaders.recursive_url_loader import RecursiveUrlLoader
from bs4 import BeautifulSoup as Soup
def read_data_from_url(url):
try:
loader = RecursiveUrlLoader(url=url, max_depth=2, extractor=lambda x: Soup(x, "html.parser").text)
text = loader.load()
return text
except Exception as e:
return f"Error: {str(e)}"
def get_table_data(quiz_str):
#convert quiz from string to dictinary
quiz_dict=json.loads(quiz_str)
quiz_table_data=[]
#iterate over the quiz dictionary and extract the required information
for key, value in quiz_dict.items():
mcq = value["mcq"]
options = " | ".join(
[
f"{option}: {option_value}"
for option, option_value in value["options"].items()
]
)
correct = value["correct"]
quiz_table_data.append({"MCQ": mcq, "Choices": options, "Correct": correct})
return quiz_table_data
|