Spaces:
Running
Running
File size: 1,092 Bytes
4cc0ea8 |
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 |
import os
import tempfile
import subprocess
from typing import Optional, Tuple, List
import pytube
from src.video_processing import extract_audio_from_video
from src.quiz_processing import analyze_document
import docx
import PyPDF2
import re
def parse_quiz_content(quiz_text):
questions = []
lines = quiz_text.split('\n')
current_question = None
for line in lines:
line = line.strip()
if not line:
continue
q_match = re.match(r'^(?:\d+\.|\[?Q\d+\]?\.?)\s+(.*)', line, re.IGNORECASE)
if q_match:
if current_question:
questions.append(current_question)
current_question = {"question": q_match.group(1), "answer": ""}
elif current_question and line.lower().startswith(("answer:", "a:", "ans:")):
answer_text = re.sub(r'^(?:answer:|a:|ans:)\s*', '', line, flags=re.IGNORECASE)
current_question["answer"] = answer_text.strip()
if current_question:
questions.append(current_question)
return {"questions": questions}
|