Spaces:
Runtime error
Runtime error
Update pipelines.py
Browse files75 unmodified lines7677787980811 unmodified line8384858687888975 unmodified linesreturn quiz_generation_pipelinedef generate_quiz(url):pipeline = generate_quiz_pipeline()try:1 unmodified lineif "generator" in results and "replies" in results["generator"]:#raw_reply = results["generator"]["replies"][0]reply = results["generator"]["replies"][0]raw_reply = reply.content if hasattr(reply, "content") else str(reply)# Extract the JSON part of the replyjson_start = raw_reply.find("{")75 unmodified lines7677787980818283848586878889909192939495969798991001011021031041051 unmodified line10710810911011111211375 unmodified linesreturn quiz_generation_pipelineimport reimport jsondef clean_llm_json(s: str) -> str:s = s.strip()# Strip ```json ... ``` fences if presentif s.startswith("```"):# remove leading ```... lines = re.sub(r"^```[a-zA-Z0-9]*\s*", "", s)# remove trailing ```s = re.sub(r"\s*```$", "", s)# If it looks like a Python dict with single quotes only, convert to double quotesif s.startswith("{") and "'" in s and '"' not in s:s = s.replace("'", '"')# Remove trailing commas before } or ]s = re.sub(r",\s*}", "}", s)s = re.sub(r",\s*]", "]", s)return sdef generate_quiz(url):pipeline = generate_quiz_pipeline()try:1 unmodified lineif "generator" in results and "replies" in results["generator"]:#raw_reply = results["generator"]["replies"][0]reply = results["generator"]["replies"][0]raw_reply = getattr(reply, "text", str(reply)) # ChatMessage.text is the canonical field# Extract the JSON part of the replyjson_start = raw_reply.find("{")
pipelines.py+25-1