import gradio as gr import os import sys import json import re # Ensure the current directory is in the path current_dir = os.path.dirname(os.path.abspath(__file__)) sys.path.append(current_dir) from smart_tutor_core import crew # ---------------------------------------------------------------------- # Helper: Parse Output # ---------------------------------------------------------------------- def parse_agent_output(raw_output: str): """ Tries to parse JSON from the raw string output. Returns (data_dict, is_json). """ data = None try: data = json.loads(raw_output) return data, True except json.JSONDecodeError: # Try finding JSON block match = re.search(r"(\{.*\})", raw_output, re.DOTALL) if match: try: data = json.loads(match.group(1)) return data, True except: pass return raw_output, False def clean_text(text: str) -> str: """ Aggressively removes markdown formatting to ensure clean text display. Removes: **bold**, __bold__, *italic*, _italic_, `code` """ if not text: return "" text = str(text) # Remove bold/italic markers text = re.sub(r"\*\*|__|`", "", text) text = re.sub(r"^\s*\*\s+", "", text) # Remove leading list asterisks if any return text.strip() # ---------------------------------------------------------------------- # Helper: Format Text Output for Display # ---------------------------------------------------------------------- def format_text_output(raw_text): """ Converts raw agent text (markdown-ish) into beautifully styled HTML inside a summary-box. """ if not raw_text: return "" text = str(raw_text).strip() # Convert markdown headings to HTML text = re.sub(r"^### (.+)$", r"
Your intelligent companion for learning and assessment