import sys try: import audioop except ImportError: # Mocking audioop for Python 3.13 compatibility class MockAudioop: def getsample(self, *args, **kwargs): return 0 def max(self, *args, **kwargs): return 0 def minmax(self, *args, **kwargs): return (0, 0) def avg(self, *args, **kwargs): return 0 sys.modules["audioop"] = MockAudioop() # Fix for Hugging Face Hub HfFolder disappearance in Gradio import huggingface_hub if not hasattr(huggingface_hub, "HfFolder"): class MockHfFolder: @staticmethod def get_token(): return None @staticmethod def save_token(token): pass @staticmethod def delete_token(): pass huggingface_hub.HfFolder = MockHfFolder import gradio as gr import os 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