#!/usr/bin/env python3 """ GenAI Specialization - Main Gradio Application Coursera-style interactive learning platform with live demos """ import gradio as gr import os import sys import subprocess from pathlib import Path import json import time import random from datetime import datetime # Try importing optional dependencies try: import torch import transformers TORCH_AVAILABLE = True except ImportError: TORCH_AVAILABLE = False print("ā ļø PyTorch not available - some features disabled") class GenAICourseApp: def __init__(self): self.course_root = Path(__file__).parent self.course_structure = self.load_course_structure() def load_course_structure(self): """Load course structure from JSON or use default""" return { "1": { "title": "Module 1: Foundations of AI & ML", "emoji": "š", "description": "Master the fundamentals of Machine Learning, Neural Networks, and Deep Learning", "lessons": [ "Introduction to AI/ML", "Neural Networks Architecture", "Backpropagation Deep Dive", "Gradient Descent Variants", "Bias-Variance Tradeoff", "Model Optimization" ], "notebooks": [ "01_Foundations/01_Introduction_to_AI_ML/notebooks/ml_basics_intro.ipynb", "01_Foundations/02_Neural_Networks_Deep_Dive/notebooks/build_nn_scratch.ipynb", "01_Foundations/03_Model_Optimization/notebooks/bias_variance_tradeoff.ipynb" ], "color": "#FF6B6B" }, "2": { "title": "Module 2: Advanced ML Techniques", "emoji": "š", "description": "Explore Reinforcement Learning and Computer Vision", "lessons": [ "RL Fundamentals", "Q-Learning & Policy Gradients", "CNN Architectures", "Transfer Learning", "Object Detection", "Image Generation" ], "notebooks": [ "02_Advanced_ML_Techniques/01_Reinforcement_Learning/notebooks/q_learning_intro.ipynb", "02_Advanced_ML_Techniques/02_Computer_Vision/notebooks/cnn_from_scratch.ipynb" ], "color": "#4ECDC4" }, "3": { "title": "Module 3: NLP Fundamentals", "emoji": "š", "description": "Master Natural Language Processing and Attention Mechanisms", "lessons": [ "Text Preprocessing", "Word Embeddings", "RNNs & LSTMs", "Attention Mechanism", "Seq2Seq Models", "Transformer Basics" ], "notebooks": [ "03_NLP_Fundamentals/01_NLP_Basics/notebooks/nlp_preprocessing.ipynb", "03_NLP_Fundamentals/02_Sequence_Models/notebooks/attention_visualization.ipynb" ], "color": "#FFE66D" }, "4": { "title": "Module 4: Generative AI Core", "emoji": "šØ", "description": "Deep dive into Transformers, LLMs, and Generative AI", "lessons": [ "Introduction to GenAI", "Transformer Architecture", "Self-Attention & Multi-Head", "Positional Encoding", "LLM Fundamentals", "Arguments of LLM" ], "notebooks": [ "04_Generative_AI_Core/02_Transformer_Architecture/notebooks/transformer_from_scratch.ipynb", "04_Generative_AI_Core/03_LLM_Fundamentals/notebooks/llm_parameters_explained.ipynb" ], "color": "#6B5B95" }, "5": { "title": "Module 5: Advanced LLM Techniques", "emoji": "ā”", "description": "Fine-tuning, RAG, and LLM Optimization", "lessons": [ "Fine-tuning Strategies", "LoRA & QLoRA", "RAG Architecture", "Retrieval Strategies", "Model Compression", "Faster Inference" ], "notebooks": [ "05_Advanced_LLM_Techniques/01_Fine_Tuning_LLMs/notebooks/lora_finetuning.ipynb", "05_Advanced_LLM_Techniques/02_RAG_Systems/notebooks/rag_pipeline_basic.ipynb", "05_Advanced_LLM_Techniques/03_LLM_Optimization/notebooks/quantization_basics.ipynb" ], "color": "#F08A5D" }, "6": { "title": "Module 6: Practical GenAI", "emoji": "š", "description": "Hands-on projects and deployment strategies", "lessons": [ "GenAI Applications", "Prompt Engineering", "LangChain & Agents", "Model Deployment", "HF Hub Integration", "Capstone Projects" ], "notebooks": [ "06_Practical_GenAI/01_Leveraging_GenAI/notebooks/langchain_intro.ipynb", "06_Practical_GenAI/02_Model_Training_Deployment/notebooks/deployment_strategies.ipynb" ], "color": "#88B04B" } } def launch_notebook(self, notebook_path): """Launch Jupyter notebook""" try: full_path = self.course_root / notebook_path if full_path.exists(): subprocess.Popen([sys.executable, "-m", "jupyter", "notebook", str(full_path)]) return f"ā Launched: {full_path.name}" else: return f"ā Notebook not found: {notebook_path}" except Exception as e: return f"ā Error: {str(e)}" def get_module_overview(self, module_key): """Get formatted module overview""" module = self.course_structure[module_key] overview = f""" # {module['emoji']} {module['title']} {module['description']} ## š Lessons """ for i, lesson in enumerate(module['lessons'], 1): overview += f"\n{i}. {lesson}" overview += f""" ## š Notebooks """ for i, nb in enumerate(module['notebooks'], 1): nb_name = Path(nb).name overview += f"\n{i}. `{nb_name}`" return overview def rag_demo(self, query): """Simple RAG demo for HF Space""" knowledge_base = { "gen ai": "**Generative AI** refers to deep learning models that can generate text, images, code, and more. Popular models include GPT-4, Llama 2, Claude, and Gemini.", "llm": "**Large Language Models (LLMs)** are foundation models trained on massive text data (often trillions of tokens). They use transformer architecture and can perform various tasks without task-specific training.", "rag": "**Retrieval-Augmented Generation (RAG)** combines retrieval systems with LLMs. It searches a knowledge base for relevant documents and provides them as context to the LLM, enabling accurate, up-to-date responses.", "fine tuning": "**Fine-tuning** adapts pre-trained models to specific tasks by continuing training on domain-specific datasets. PEFT methods like LoRA make this efficient by updating only 0.1% of parameters.", "transformer": "**Transformers** use self-attention to process sequences in parallel. Key components: multi-head attention, positional encoding, feed-forward networks, and layer normalization.", "attention": "**Attention mechanisms** allow models to focus on relevant parts of input. Self-attention computes relationships between all tokens, while cross-attention attends to encoder outputs.", "backpropagation": "**Backpropagation** computes gradients using the chain rule, enabling efficient training of neural networks through gradient descent.", "gradient descent": "**Gradient descent** optimizes model parameters by moving in the direction of steepest descent. Variants: SGD, Adam, RMSprop, AdaGrad.", "lora": "**LoRA (Low-Rank Adaptation)** freezes base weights and injects trainable rank decomposition matrices, reducing trainable parameters by 1000x while maintaining performance." } query_lower = query.lower() relevant_info = [] for key, value in knowledge_base.items(): if key in query_lower: relevant_info.append(value) if relevant_info: response = "## š Retrieved Information\n\n" response += "\n\n".join(relevant_info) if len(relevant_info) > 1: response += "\n\n---\nš” *Multiple relevant documents found*" else: response = """ā **I don't have specific information on that topic.** Try asking about: - **Gen AI** - Generative AI fundamentals - **LLM** - Large Language Models - **RAG** - Retrieval-Augmented Generation - **Fine-tuning** - LoRA, PEFT methods - **Transformer** - Architecture & attention - **Backpropagation** - Gradient computation """ return response # Create the Gradio interface def create_interface(): app = GenAICourseApp() # Custom CSS custom_css = """ """ with gr.Blocks(title="GenAI Specialization", theme=gr.themes.Soft()) as demo: gr.HTML(custom_css) gr.Markdown(""" # š§ Generative AI Specialization ### *Your Complete Learning Path from Fundamentals to Advanced LLMs* --- """) # Stats row with gr.Row(): with gr.Column(): gr.Markdown("""
Modules
Lessons
Capstone Projects