๐ŸŽ“ Certificate 1 ยท AI Career Ladder ยท Batch 2026

THE
Generative AI
Practitioner

Build Real AI Applications ยท Master Prompt Engineering ยท Deploy with Python

11Chapters
8Weeks
50+Projects

Muhammad Rustam ยท Founder & Lead Instructor
AI By Tech Academy ยท Karachi, Pakistan ยท aibytec.com

Navigation

Table of Contents

Click any chapter to jump directly to that section

Foreword

Welcome from AI By Tech

aibytec.com ยท Karachi, Pakistan ยท Batch 2026

AI By Tech (aibytec.com) is Pakistan's applied AI education platform, dedicated to training the next generation of AI practitioners, developers, and architects. We don't just teach theory โ€” every class, every chapter, and every project in this book is built around real tools, real workflows, and real deployments.

This book โ€” The Generative AI Practitioner โ€” is the complete companion text for Certificate 1 of the AI Career Ladder program. It is designed for one purpose: to take any motivated person from zero knowledge of AI to building and deploying their own AI-powered applications, in eight weeks.

Knowledge increases by sharing, not by saving.

โ€” Muhammad Rustam, Founder ยท AI By Tech Academy

The AI revolution is happening now. It is not coming. It arrived. The students who understand Generative AI at the practitioner level today will be the architects, developers, and entrepreneurs who shape the next decade. This book is your on-ramp.

๐Ÿ“˜ How to Use This Book
  • Each chapter maps to one or more class sessions from the 8-week curriculum.
  • Every concept is followed immediately by a Try It Now hands-on exercise.
  • All code examples run in Google Colab โ€” no installation required.
  • Chapter summaries, key terms, and review questions end every chapter.
โœ… Prerequisites
  • Basic computer literacy โ€” you can use a browser, create files, send emails.
  • A Google account โ€” for Google Colab (free, runs in browser).
  • No prior coding experience required. Python basics are taught from scratch.
  • Curiosity and willingness to experiment. AI rewards learners who try things.
Part One

Foundations

Chapter 01

What is Generative AI?

The Revolution That Is Reshaping Everything

We are living through a genuine inflection point. Not another hype cycle โ€” a structural shift in how humans create, communicate, and build. Generative AI is the engine of this shift. This chapter gives you the mental model and vocabulary you need to understand it clearly.

1.1 The Three Waves of AI

EraWaveWhat ChangedExample
1950sโ€“1990sRule-Based AIProgrammers wrote explicit rules. Computers followed them. No learning.Chess programs, expert systems
1990sโ€“2015Machine LearningComputers learned patterns from data. No explicit rules needed.Spam filters, image recognition
2017โ€“PresentGenerative AIComputers don't just recognize patterns โ€” they create.ChatGPT, Claude, Midjourney
๐ŸŽฏ Core Definition

Generative AI is a class of artificial intelligence that creates new content โ€” text, code, images, audio, video, or data โ€” by learning patterns from enormous amounts of existing human-created content.

It does not just analyze or classify. It generates. It creates. It produces. These systems have learned so much about human language, logic, and creativity that they can produce outputs indistinguishable from โ€” and sometimes superior to โ€” human work.

1.2 Why 2025 Is Different โ€” The Convergence

Three independent trends converged simultaneously for the first time in history:

1
Capability Crossed the Production Threshold
AI systems began passing bar exams, writing production code, generating publication-quality research, and scoring in the top percentile of human participants in competitive programming.
2
Adoption Passed the Tipping Point
Developer surveys showed more than 80% of professional developers actively using AI coding tools daily. ChatGPT reached 100 million users faster than any product in history.
3
Enterprise Investment Became Structural
Global investment in AI-native infrastructure exceeded $200 billion in 2024 alone. Companies didn't experiment with AI โ€” they bet their roadmaps on it.

1.3 The Generative AI Family

๐Ÿ“ Text Generation
ChatGPT ยท Claude ยท Gemini ยท Llama
Writing, summarizing, translating, coding, answering questions, drafting legal documents, stories.
๐ŸŽจ Image Generation
Midjourney ยท DALL-E 3 ยท Stable Diffusion
Creating artwork, product mockups, marketing visuals, illustrations from text descriptions.
๐Ÿ’ป Code Generation
GitHub Copilot ยท Claude Code ยท Cursor
Writing functions, debugging, explaining code, generating entire applications from specifications.
๐ŸŽต Audio Generation
ElevenLabs ยท Suno ยท Whisper
Cloning voices, generating music, text-to-speech for any language, podcast creation.
๐ŸŽฌ Video Generation
Sora ยท Runway ยท Pika
Creating short videos from text prompts, animating images, generating cinematic scenes.
๐Ÿ“Š Data Generation
Various specialized tools
Synthetic training data, realistic tabular datasets, augmented data for ML pipelines.

1.4 The Models You Will Use

ModelStrengthWhen You'll Use It
ChatGPT (OpenAI)General purpose, huge ecosystemWriting, coding, analysis โ€” Chapters 2โ€“4
Claude (Anthropic)Long context, structured outputDocument analysis, complex reasoning โ€” throughout
DeepSeekEfficient, strong at codingCode generation, cost-conscious apps
Llama 3 (Meta)Open source, freeVia Groq API for high-speed apps โ€” Chapter 5
Mixtral (Mistral)Fast, multilingualProduction apps needing speed & low cost
Gemini (Google)Multimodal โ€” text + imagesImage understanding, Google Workspace integration
๐Ÿ‡ต๐Ÿ‡ฐ AI in Pakistan โ€” Real Opportunities
  • Freelancing: AI developers earn $25โ€“$100/hour on Upwork/Fiverr for chatbots and automation.
  • Enterprise AI Consulting: Pakistani companies are investing in AI automation โ€” consultants are in demand.
  • AI-Augmented Services: Marketing, content, translation, legal โ€” every service becomes 10x faster.
  • Remote Jobs: AI skills qualify you for remote roles paying international salaries.

๐Ÿ“ Chapter 1 Summary

Generative AI creates new content โ€” text, code, images, audio, video โ€” by learning from vast human data.
The 2025 convergence of capability + adoption + enterprise investment is real and structural.
The Gen AI family covers six output types: text, image, code, audio, video, and data.
You will work with ChatGPT, Claude, Llama, Mixtral, and Gemini throughout this course.
Pakistan has immediate opportunities in freelancing, consulting, EdTech, and product development.
Chapter 02

How Large Language Models Work

Transformers, Tokens, Temperature & Training

You don't need a PhD to use Generative AI effectively. But understanding how LLMs work at a conceptual level โ€” what they see, how they think, what their limitations are โ€” makes you dramatically better at using them. No mathematics required.

2.1 Tokens โ€” What AI Actually Reads

When you type a message to ChatGPT or Claude, the AI doesn't see your words. It sees tokens. A token is roughly 3โ€“4 characters, or about 75% of a word on average.

๐Ÿ“Œ Tokenization Examples

"Hello" โ†’ 1 token  |  "Generative" โ†’ 2โ€“3 tokens  |  "Muhammad Rustam" โ†’ 4 tokens

Rule of thumb: 1,000 tokens โ‰ˆ 750 words โ‰ˆ about 1.5 pages of text.

GPT-4 has a context window of 128,000 tokens โ€” about 200 pages of text at once.

2.2 The Transformer Architecture

Every major LLM today โ€” GPT-4, Claude, Gemini, Llama โ€” is built on the Transformer architecture, invented by Google researchers in 2017 in a paper titled "Attention Is All You Need."

Before Transformers, AI models read text sequentially โ€” word by word, left to right. By the time they reached word 100, they had nearly forgotten word 1. Transformers changed this by introducing attention โ€” the model looks at all words simultaneously and decides which are most relevant to each other.

๐Ÿ”ง How Training Works (Simplified)
1
Data Collection
Collect a huge corpus of text โ€” web pages, books, code, papers โ€” trillions of words.
2
Prediction Task
Show the model text with the last word hidden. Ask: "What comes next?"
3
Backpropagation
Compare the guess to the real answer. Adjust the weights to be more accurate. Repeat billions of times.
4
Fine-Tuning (RLHF)
Use human feedback to make the model helpful, harmless, and honest.

2.3 Temperature โ€” Creativity vs Consistency

TemperatureEffectBest Use
0.0Fully deterministic โ€” same input = same output every timeFact extraction, classification, data parsing
0.3โ€“0.5Mostly consistent with slight variationSummarization, translation, professional writing
0.7โ€“0.8Balanced โ€” the default for most appsGeneral chat, Q&A, content generation
1.0โ€“1.2Creative and variedBrainstorming, story generation, ideation

2.4 Hallucination โ€” The Most Critical Limitation

A language model doesn't know what it doesn't know. It predicts plausible text โ€” not verified truth. Confidence in the output does not indicate accuracy.

โ€” AI Practitioners' Maxim

Hallucination is when an AI model generates information that sounds confident but is factually incorrect or completely fabricated. It is the most important limitation to understand.

โš ๏ธ How to Minimize Hallucination
  • Ask the model to cite sources โ€” then verify those sources independently.
  • Use RAG (Chapter 9) to ground the model in your verified documents.
  • Set temperature to 0 for fact-critical tasks.
  • Include in your prompt: "If you are not certain, say I don't know."
  • Use AI for drafting and ideation; verify final facts with authoritative sources.

๐Ÿ“ Chapter 2 Summary

LLMs process text as tokens (~4 characters each). Token counts determine cost and context limits.
The Transformer architecture uses attention โ€” reading all words simultaneously rather than sequentially.
Training: predict the next token across trillions of words, then refined with human feedback (RLHF).
Temperature controls creativity vs consistency โ€” lower for facts, higher for creative work.
Hallucination is the critical limitation โ€” LLMs generate plausible text, not verified truth.
Chapter 03

Python for AI Practitioners

The Language That Runs the World's AI

Python is the language of AI. Not because it is the fastest โ€” it isn't. Python dominates AI because it is readable, expressive, and has the most mature ecosystem of AI libraries ever assembled. If you learn one programming language for AI, it's Python.

๐Ÿš€ Getting Started with Google Colab
  1. Go to colab.research.google.com
  2. Sign in with your Google account
  3. Click "New Notebook"
  4. Type code in a cell and press Shift+Enter to run
  5. Results appear immediately below โ€” no installation required!

3.1 Variables & Data Types

PYTHON
# Variables store values โ€” Python figures out the type automatically
name     = "Muhammad Rustam"   # string (text)
age      = 28                  # integer (whole number)
rating   = 4.8                 # float (decimal)
enrolled = True                 # boolean

# f-strings โ€” the cleanest way to format text (essential for AI prompts!)
print(f"Hello, {name}! Your rating is {rating}/5.0")

3.2 Lists, Loops & Conditions

PYTHON
# Lists โ€” store multiple items
ai_tools = ["ChatGPT", "Claude", "Gemini", "Llama"]
ai_tools.append("Mistral")
print(ai_tools[0])   # ChatGPT (index starts at 0)

# For loops
for tool in ai_tools:
    print(f"Tool: {tool}")

# If / elif / else
score = 85
if score >= 90:
    grade = "A"
elif score >= 80:
    grade = "B"
else:
    grade = "Fail"
print(f"Grade: {grade}")  # Grade: B

3.3 Functions & Error Handling

PYTHON
# Define reusable functions
def ask_ai(question, model="llama3"):
    """Send a question to an AI model and return the answer."""
    try:
        response = client.chat.completions.create(
            model=model,
            messages=[{"role": "user", "content": question}]
        )
        return response.choices[0].message.content
    except Exception as e:
        print(f"Error: {e}")
        return "Could not get a response. Please try again."

answer = ask_ai("What is the capital of Pakistan?")
print(answer)  # Islamabad

3.4 Key AI Libraries

LibraryInstallWhat It Does
openaipip install openaiOfficial OpenAI SDK โ€” call GPT-4, DALL-E, Whisper
anthropicpip install anthropicOfficial Anthropic SDK โ€” call Claude models
groqpip install groqGroq API โ€” Llama & Mixtral at ultra-fast speed
streamlitpip install streamlitBuild interactive AI web apps in pure Python
gradiopip install gradioAI demo interfaces with drag-and-drop UI
transformerspip install transformersHugging Face models โ€” run 500k+ models locally
pandaspip install pandasData manipulation โ€” read CSV, Excel, JSON

๐Ÿ“ Chapter 3 Summary

Python is the #1 language for AI โ€” readable, powerful, and unmatched library ecosystem.
Google Colab provides free Python in the browser โ€” no installation needed for any exercise.
Core Python: variables, lists, dictionaries, if/else, loops, functions โ€” you'll use all of these daily.
f-strings make formatting text easy โ€” essential for building AI prompts with variables.
Always use try/except for API calls โ€” networks fail, rate limits happen, keys expire.
Part Two

Tools & Techniques

Chapter 04

Prompt Engineering

Talk to AI Like a Pro โ€” The Developer Superpower

The quality of AI output is determined almost entirely by the quality of the input. Invest in the prompt, reap in the result.

โ€” Muhammad Rustam, AI By Tech

Prompt Engineering is the art and science of crafting inputs to AI models that consistently produce high-quality, accurate, and useful outputs. Companies pay $50โ€“$150 per hour for skilled prompt engineers. This chapter makes you one.

4.1 Why Prompting Matters

โŒ Weak Prompt

"Write about AI"

Output: Vague, generic 3-paragraph summary. Not actionable.

โœ… Strong Prompt

"Write a 500-word blog post for Pakistani IT students about how learning Generative AI in 2025 leads to freelancing on Upwork. Use a motivational tone, include 3 specific job titles with estimated hourly rates, and end with a clear call to action."

4.2 The CRAFT Framework

Every excellent prompt contains five elements. Use CRAFT as your checklist:

C
Context
Background info the AI needs to understand your situation
R
Role
Who or what the AI should act as
A
Action
The specific task you want done
F
Format
How the output should be structured
T
Tone
The style and register of the output

4.3 Prompting Techniques

Zero-Shot โ€” Simple, direct, no examples

PROMPT
Classify the sentiment of this text as Positive, Negative, or Neutral:
"The new AI course from AiBytec is absolutely amazing!"

Few-Shot โ€” Give examples, get better results

PROMPT
Classify reviews as Positive, Negative, or Neutral.

Examples:
"Best laptop I've owned." โ†’ Positive
"Terrible battery life."  โ†’ Negative
"Arrived on time."         โ†’ Neutral

Now classify:
"Content is deep but platform loads slowly." โ†’

Chain-of-Thought โ€” Make AI reason step-by-step

PROMPT
A company has 3 AI developers. Each completes 4 projects/month.
They earn PKR 25,000 per project.
To triple monthly revenue, how many developers do they need?

Think through this step by step before giving your final answer.

4.4 System Prompts โ€” Program Your AI App

PYTHON ยท SYSTEM PROMPT
system_prompt = """
You are EduAI, an intelligent tutoring assistant for AI By Tech Academy.

Your role:
- Help students understand Generative AI concepts clearly
- Explain technical topics using simple, relatable examples from Pakistan
- When students share code, debug it and explain the fix
- Encourage students and celebrate their progress

Constraints:
- Always respond in English with occasional Urdu phrases for warmth
- Keep explanations under 200 words unless the student asks for more
- Never write complete assignments โ€” guide students to the answer
- If you don't know something, say so clearly

Tone: Friendly, encouraging, teacher-like, culturally aware
"""

๐Ÿ“ Chapter 4 Summary

Prompt engineering is the single most impactful skill for AI practitioners โ€” companies pay $50โ€“$150/hr.
The CRAFT Framework: Context, Role, Action, Format, Tone โ€” use for every important prompt.
Zero-shot for simple tasks; Few-shot for specialized outputs; Chain-of-thought for reasoning.
Role prompting activates domain expertise patterns โ€” "Act as a senior X with N years of Y experience."
System prompts define the behavior of your AI application for all users โ€” the foundation of AI apps.
Chapter 05

Working with AI APIs

Connecting Your Apps to the World's Most Powerful AI Models

๐Ÿ“Œ What is an API?

Imagine you're in a restaurant. You (the client) tell the waiter (the API) your order. The waiter goes to the kitchen (the AI model on remote servers) and brings back your food (the generated text). You never see the kitchen. You never touch the stove.

An AI API works identically. Your Python code sends a request, the AI model processes it on a massive GPU cluster, and the response comes back โ€” in milliseconds.

5.1 API Keys โ€” Security First

PYTHON
# โŒ WRONG โ€” Never hardcode API keys in your code
client = OpenAI(api_key="sk-abc123...")  # Anyone who sees your code can use your key!

# โœ… CORRECT โ€” Use environment variables
import os
from dotenv import load_dotenv

load_dotenv()  # Loads from a .env file
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))

# .env file (add to .gitignore, NEVER commit to GitHub):
# OPENAI_API_KEY=sk-abc123...
# GROQ_API_KEY=gsk_abc123...

5.2 The Groq API โ€” 10x Faster Inference

ModelSpeed on Groqvs Standard
Llama 3 8B~700 tokens/second10โ€“15x faster
Mixtral 8x7B~500 tokens/second8โ€“12x faster
Llama 3 70B~300 tokens/second5โ€“8x faster
PYTHON ยท GROQ API
from groq import Groq
import os

client = Groq(api_key=os.getenv("GROQ_API_KEY"))

def fast_ai(prompt, model="llama3-8b-8192"):
    response = client.chat.completions.create(
        model=model,
        messages=[{"role": "user", "content": prompt}],
        temperature=0.7, max_tokens=1024
    )
    return response.choices[0].message.content

answer = fast_ai("What are the top 5 AI skills for Pakistani developers in 2025?")
print(answer)

5.3 Multi-Turn Conversations

PYTHON ยท CHAT WITH MEMORY
conversation_history = []

def chat(user_input, system="You are a helpful AI assistant."):
    if not conversation_history:
        conversation_history.append({"role": "system", "content": system})
    conversation_history.append({"role": "user", "content": user_input})
    response = client.chat.completions.create(
        model="llama3-8b-8192", messages=conversation_history
    )
    ai_reply = response.choices[0].message.content
    conversation_history.append({"role": "assistant", "content": ai_reply})
    return ai_reply

print(chat("My name is Rustam and I am from Karachi."))
print(chat("What is my name and where am I from?"))  # AI remembers!

๐Ÿ“ Chapter 5 Summary

APIs let your code access AI models running on powerful remote servers via the internet.
API keys are secrets โ€” always use environment variables, never hardcode them in code.
Groq API: Llama 3, Mixtral โ€” 10x faster than competitors via custom LPU hardware. Free tier is generous.
Anthropic API: Claude โ€” best for long documents, structured output, and complex reasoning.
Conversation history must be sent with every API call โ€” LLMs have no built-in memory between calls.
Chapter 06

Hugging Face & Open-Source Models

The GitHub of AI โ€” 500,000+ Free Models for Every Task

Hugging Face is to AI what GitHub is to code โ€” the world's central repository for machine learning models, datasets, and demos. With over 500,000 models, 150,000 datasets, and 100,000 interactive demos, it is the most important resource in the open-source AI ecosystem. And most of it is completely free.

6.1 The Transformers Library โ€” Your AI Swiss Army Knife

PYTHON ยท HUGGING FACE PIPELINES
from transformers import pipeline

# TEXT GENERATION
generator = pipeline("text-generation", model="gpt2")
result = generator("The future of AI in Pakistan will", max_length=100)
print(result[0]["generated_text"])

# SENTIMENT ANALYSIS
classifier = pipeline("sentiment-analysis")
result = classifier("This AiBytec course is the best investment I've made!")
print(result)  # [{'label': 'POSITIVE', 'score': 0.9998}]

# TRANSLATION โ€” English to Urdu
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-ur")
result = translator("Artificial Intelligence is transforming education in Pakistan.")
print(result[0]["translation_text"])

# QUESTION ANSWERING
qa = pipeline("question-answering")
result = qa(question="Where is AiBytec based?",
             context="AiBytec is Pakistan's premier AI education platform based in Karachi.")
print(result["answer"])  # Karachi

6.2 Embeddings โ€” Teaching AI to Understand Meaning

Embeddings are numerical representations of text that capture meaning. Two sentences that mean similar things will have embeddings that are mathematically close. Embeddings are the foundation of semantic search, RAG systems, and recommendations.

PYTHON ยท SEMANTIC SIMILARITY
from sentence_transformers import SentenceTransformer
from sklearn.metrics.pairwise import cosine_similarity

model = SentenceTransformer("all-MiniLM-L6-v2")

sentences = [
    "How do I learn Python for AI?",
    "What is the best way to start coding in Python?",
    "What is the capital city of Australia?"
]
embeddings = model.encode(sentences)

sim_01 = cosine_similarity([embeddings[0]], [embeddings[1]])[0][0]
sim_02 = cosine_similarity([embeddings[0]], [embeddings[2]])[0][0]
print(f"Similarity (Python questions): {sim_01:.3f}")  # ~0.85
print(f"Similarity (unrelated): {sim_02:.3f}")       # ~0.12
๐Ÿ–ฅ๏ธ Ollama โ€” Run AI Completely Offline

For privacy-sensitive projects, Ollama lets you run powerful AI models entirely on your local machine โ€” no internet, no API costs, no data leaving your computer.

  1. Download from ollama.ai (Windows, Mac, Linux)
  2. Run: ollama pull llama3
  3. Chat: ollama run llama3
  4. Or use the Python API: import ollama

Minimum specs: 8GB RAM. GPU helps but CPU works fine for small models.

๐Ÿ“ Chapter 6 Summary

Hugging Face is the world's central hub for AI models, datasets, and demos โ€” mostly free.
The pipeline() function gives a unified interface for 100+ task types โ€” text, image, audio, video.
Embeddings are numerical representations of meaning โ€” the foundation of semantic search and RAG.
sentence-transformers: all-MiniLM-L6-v2 is fast, free, and accurate for similarity tasks.
Ollama enables fully local AI inference โ€” no API costs, no internet, complete privacy.
Part Three

Building Applications

Chapter 07

Build AI Web Apps with Streamlit

From Python Script to Deployed Web App in Hours

Streamlit converts Python scripts into web applications. No HTML. No CSS. No JavaScript. Pure Python โ€” and the results look professional. Over 1 million apps have been deployed on Streamlit Community Cloud.

7.1 Your First Streamlit App

PYTHON ยท app.py
import streamlit as st
from groq import Groq
import os

st.set_page_config(page_title="AiBytec AI App", page_icon="๐Ÿค–")
st.title("๐Ÿค– AI Assistant โ€” AiBytec")

client = Groq(api_key=os.getenv("GROQ_API_KEY"))

question = st.text_area("Ask me anything", height=120)
model    = st.selectbox("Model", ["llama3-70b-8192", "mixtral-8x7b-32768"])
temp     = st.slider("Temperature", 0.0, 1.5, 0.7)

if st.button("โœจ Get Answer", type="primary"):
    with st.spinner("AI is thinking..."):
        response = client.chat.completions.create(
            model=model,
            messages=[{"role": "user", "content": question}],
            temperature=temp
        )
        answer = response.choices[0].message.content
    st.success("Done!")
    st.markdown(answer)
    st.download_button("๐Ÿ’พ Download Answer", answer, "answer.txt")

# Run with: streamlit run app.py

7.2 Core Streamlit Components

ComponentCodeUse For
Text Inputst.text_input("Label")Short text โ€” names, search queries
Text Areast.text_area("Label", height=150)Long text โ€” documents, prompts
Select Boxst.selectbox("Label", ["A","B"])Dropdown โ€” model choice, options
Sliderst.slider("Label", 0.0, 2.0, 0.7)Numeric range โ€” temperature
File Uploadst.file_uploader("Upload", type=["pdf"])Documents, images for AI analysis
Columnscol1, col2 = st.columns(2)Side-by-side layout
Sidebarwith st.sidebar:Settings, API key input
Spinnerwith st.spinner("Thinking..."):Show loading while AI responds
๐Ÿš€ Deploy Free in 3 Steps
  1. Push your code to GitHub (include app.py + requirements.txt)
  2. Go to share.streamlit.io โ†’ sign in with GitHub
  3. Select repo, add API keys as Secrets, click Deploy โ€” your app is live!

๐Ÿ“ Chapter 7 Summary

Streamlit converts Python scripts into web apps โ€” no HTML, CSS, or JavaScript needed.
Core inputs: text_input, text_area, selectbox, slider, file_uploader, button, columns.
Use st.spinner() to show loading state while waiting for AI API responses.
Deploy free on Streamlit Community Cloud โ€” one public URL to share your app with anyone.
Never commit API keys to GitHub โ€” always add them as Streamlit Cloud Secrets.
Chapter 08

Build AI Interfaces with Gradio

Drag-and-Drop AI Demos โ€” Images, Audio, Chat, and More

Gradio is Hugging Face's app-building framework, designed specifically for AI demos. Where Streamlit excels at dashboards, Gradio is optimized for input-output AI demos. Build a voice-enabled chatbot in under 20 lines.

8.1 Gradio vs Streamlit โ€” When to Use Each

Gradio โ€” Use When
  • Building AI input-output demos
  • Voice, image, or video interfaces
  • Sharing ML models on Hugging Face Spaces
  • Quick prototypes to share with stakeholders
Streamlit โ€” Use When
  • Building data dashboards and analytics
  • Multi-page web applications with state
  • Complex workflows with database connections
  • Production apps with rich layouts

8.2 Chatbot with Memory

PYTHON ยท GRADIO CHATBOT
import gradio as gr
from groq import Groq
import os

client = Groq(api_key=os.getenv("GROQ_API_KEY"))

SYSTEM = """You are AiBytec Assistant โ€” a helpful AI tutor.
You help Pakistani students learn Generative AI and Python.
Be encouraging, give clear explanations, use local examples."""

def chat(user_message, history):
    messages = [{"role": "system", "content": SYSTEM}]
    for user, assistant in history:
        messages.append({"role": "user", "content": user})
        messages.append({"role": "assistant", "content": assistant})
    messages.append({"role": "user", "content": user_message})
    response = client.chat.completions.create(
        model="mixtral-8x7b-32768", messages=messages
    )
    return response.choices[0].message.content

demo = gr.ChatInterface(
    fn=chat, title="๐ŸŽ“ AiBytec AI Tutor",
    examples=[
        "What is the difference between supervised and unsupervised learning?",
        "How do I build my first AI app in Python?",
        "What AI skills should I learn for a job in 2025?"
    ],
    theme=gr.themes.Soft()
)
demo.launch(share=True)  # share=True โ†’ public URL!
โ˜๏ธ Deploy Free on Hugging Face Spaces
  1. Create a free account at huggingface.co
  2. Click "New Space" โ†’ select "Gradio" as the SDK
  3. Upload app.py and requirements.txt, or connect GitHub
  4. Add API keys as Repository Secrets (Settings โ†’ Secrets)
  5. Your app is live at: huggingface.co/spaces/your-username/your-app

๐Ÿ“ Chapter 8 Summary

Gradio is optimized for AI input-output demos โ€” images, audio, text, and multimodal interfaces.
gr.Interface() wraps any Python function with a UI in under 10 lines of code.
gr.ChatInterface() automatically manages conversation history for chatbot applications.
Deploy for free on Hugging Face Spaces โ€” permanent URL, automatic scaling, no credit card.
Chapter 09

RAG โ€” Retrieval-Augmented Generation

Teaching AI to Know Your Documents

Without RAG, your AI knows everything before its training cutoff but nothing about your company, your documents, or yesterday's news. RAG fixes all three.

โ€” AI Practitioners' Maxim

9.1 The RAG Pipeline

โš™๏ธ Step-by-Step RAG Architecture

INDEXING (Done Once, Offline):

  1. Load your documents (PDF, DOCX, TXT, websites)
  2. Split documents into chunks (500โ€“1000 characters each)
  3. Embed each chunk using an embedding model (text โ†’ vectors)
  4. Store vectors in a vector database (FAISS, ChromaDB, Pinecone)

RETRIEVAL + GENERATION (Every Query):

  1. User asks a question โ†’ embed the question
  2. Search vector database โ†’ retrieve top-k most similar chunks
  3. Build prompt: [System] + [Retrieved context] + [Question]
  4. Send to LLM โ†’ get grounded, cited answer

9.2 RAG from Scratch โ€” Complete Implementation

PYTHON ยท SIMPLE RAG SYSTEM
import faiss, numpy as np
from sentence_transformers import SentenceTransformer
from groq import Groq
import os

embedder   = SentenceTransformer("all-MiniLM-L6-v2")
llm_client = Groq(api_key=os.getenv("GROQ_API_KEY"))

class SimpleRAG:
    def __init__(self):
        self.chunks = []; self.index = None

    def add_text(self, text, source="manual", chunk_size=500):
        words = text.split()
        for i in range(0, len(words), chunk_size):
            chunk = " ".join(words[i:i+chunk_size])
            if len(chunk.strip()) > 100:
                self.chunks.append({"text": chunk, "source": source})

    def build_index(self):
        texts = [c["text"] for c in self.chunks]
        embs  = embedder.encode(texts)
        self.index = faiss.IndexFlatL2(embs.shape[1])
        self.index.add(embs.astype(np.float32))

    def answer(self, question, top_k=3):
        q_emb = embedder.encode([question]).astype(np.float32)
        _, ids = self.index.search(q_emb, top_k)
        context = "\n\n".join([self.chunks[i]["text"] for i in ids[0]])
        response = llm_client.chat.completions.create(
            model="llama3-70b-8192",
            messages=[{"role": "user",
                       "content": f"Answer using ONLY the context below.\n\nCONTEXT:\n{context}\n\nQUESTION: {question}"}],
            temperature=0.1
        )
        return response.choices[0].message.content

rag = SimpleRAG()
rag.add_text("AiBytec offers Certificate 1 (Gen AI, PKR 15,000), Certificate 2 (Agentic AI, PKR 45,000). Based in Karachi.")
rag.build_index()
print(rag.answer("How much does Certificate 2 cost?"))

๐Ÿ“ Chapter 9 Summary

RAG solves the key LLM limitation โ€” connecting AI to your private, fresh, or domain-specific data.
Pipeline: Load โ†’ Chunk โ†’ Embed โ†’ Index (offline); Embed query โ†’ Search โ†’ Retrieve โ†’ Generate (online).
Vector databases store embeddings for fast semantic similarity search: FAISS, ChromaDB, Pinecone.
Keep temperature low (0.1โ€“0.3) for RAG to ensure factual, grounded responses.
Always instruct the LLM to only use provided context โ€” reduces hallucination dramatically.
Part Four

Advanced & Professional

Chapter 10

AI Safety, Ethics & Responsible Use

Building AI That Helps, Not Harms

With great capability comes great responsibility. Every AI application you build either adds to the world's trust in AI or subtracts from it. Build accordingly.

โ€” Muhammad Rustam, AI By Tech

10.1 The Core Risks of Generative AI

RiskDescriptionExample Harms
HallucinationAI generates confidently stated false informationMedical misdiagnosis, fabricated citations
Bias & DiscriminationAI reflects and amplifies biases in training dataBiased hiring tools, unfair credit scoring
Privacy ViolationAI trained on private data leaks it, or enables surveillancePersonal data exposure, deepfake abuse
MisinformationAI generates convincing fake news and propagandaElection interference, reputation destruction
Copyright InfringementAI trained on copyrighted work reproduces itPlagiarized code, copied artwork
Over-RelianceUsers stop critical thinking and blindly trust AIErrors in critical systems, skill atrophy

10.2 The 7 Principles of Responsible AI

  • Transparency โ€” Users should know they are interacting with AI. Don't disguise AI as human.
  • Fairness โ€” AI systems should produce equitable outcomes across genders, races, religions, and social groups.
  • Accountability โ€” Every AI system should have a human responsible for its actions and outcomes.
  • Privacy โ€” Collect only necessary data. Never train on sensitive personal data without explicit consent.
  • Safety โ€” AI in high-stakes domains (healthcare, legal, financial) requires human oversight and validation.
  • Beneficence โ€” Design AI to benefit users and society, not just maximize profit or engagement.
  • Non-maleficence โ€” If a feature could cause harm, don't build it โ€” regardless of how technically possible it is.
โš ๏ธ High-Stakes Domains โ€” Critical Rules

Healthcare AI: AI assists clinicians but must NEVER replace human medical judgment.
โ†’ Always add: "This is not medical advice. Consult a qualified doctor."

Legal AI: AI can draft documents but cannot provide legal advice.
โ†’ Always add: "This is not legal advice. Consult a qualified lawyer."

Financial AI: AI can analyze data but cannot guarantee returns.
โ†’ Always add: "This is not financial advice. Past performance does not guarantee future results."

๐Ÿ“ Chapter 10 Summary

The six core AI risks: hallucination, bias, privacy violation, misinformation, copyright, over-reliance.
Seven principles of responsible AI: Transparency, Fairness, Accountability, Privacy, Safety, Beneficence, Non-maleficence.
Always validate inputs โ€” length limits, blocked patterns, HTML stripping, content screening.
High-stakes domains require extra disclaimers and mandatory human review before action.
Chapter 11

Your Gen AI Portfolio โ€” Capstone Projects

Build. Deploy. Showcase. Get Hired.

Your GitHub portfolio is your new resume. Every deployed app is a job interview that runs 24/7. Build things that show what you can do โ€” don't just talk about it.

โ€” Muhammad Rustam, AI By Tech

11.1 Eight Capstone Project Ideas

01
AI Study Planner
Medium
Input subjects, exam date, hours available โ†’ AI generates a personalized study schedule. Stack: Streamlit + Groq + Claude
02
Urdu-English AI Translator
Medium
Translate text and audio between Urdu and English with cultural context. Stack: Gradio + Hugging Face + Whisper
03
Document Q&A System (RAG)
Medium-Hard
Upload a PDF and ask questions from it. Stack: Streamlit + ChromaDB + SentenceTransformers + Llama3
04
AI Resume Builder
Medium
Generate professional CVs from user data with downloadable output. Stack: Streamlit + GPT-4/Llama3
05
Business Idea Generator
Easy-Medium
Input skills and budget โ†’ AI generates 5 viable business ideas with execution plans. Stack: Gradio + Groq
06
Sentiment Dashboard
Medium-Hard
Analyze customer reviews from CSV, display sentiment trends on live charts. Stack: Streamlit + HuggingFace + Plotly
07
AI Tutoring Chatbot
Medium
Domain-specific chatbot with memory for a subject of your choice. Stack: Gradio ChatInterface + Groq + ChromaDB
08
Freelancer Rate Calculator
Easy-Medium
Input skills + experience โ†’ AI suggests optimal hourly rates for Upwork and Fiverr. Stack: Streamlit + Claude

11.2 Career Paths After Certificate 1

Prompt Engineer
PKR 80Kโ€“200K/month
Design prompts and AI workflows for enterprise applications. Required: prompt engineering, domain expertise.
AI Developer
PKR 150Kโ€“400K/month
Build AI applications using APIs, Python, and LLM frameworks. Required: Python, APIs, Streamlit/Gradio.
AI Freelancer
$25โ€“$100/hour (Upwork)
Chatbot development, AI automation, prompt engineering gigs. Start within 1 month of Certificate 1.
AI Educator
PKR 50Kโ€“500K/month
Teach AI to organizations and individuals โ€” like Muhammad Rustam at AiBytec. Recurring income.

๐Ÿ† Ready for Certificate 2?

You've completed Certificate 1: Gen AI Practitioner. Certificate 2 โ€” Agentic AI Developer โ€” teaches you to build autonomous AI agents, integrate MCP servers, and apply Spec-Driven Development with Claude Code.

Ch 01 ยท AI Agent Factory Ch 02 ยท Markdown for Agents Ch 03 ยท Claude Code & Cowork Ch 04 ยท Context Engineering Ch 05 ยท Spec-Driven Development Ch 06 ยท Seven Agent Principles Ch 07 ยท File Automation Ch 08 ยท Research Synthesis Ch 09 ยท Data Analysis Ch 10 ยท Agent Safety Ch 11 ยท AI Employee Capstone

Duration: 3 Months  |  Fee: PKR 45,000  |  Batch: After Eid 2026 (InshAllah)

Enroll at aibytec.com โ†’

๐Ÿ“ Chapter 11 Summary โ€” Congratulations! ๐ŸŽ‰

Your deployed GitHub portfolio of projects is more valuable than any certificate alone.
Eight capstone ideas covering all skill levels โ€” from AI study planners to RAG document systems.
Freelancing opportunities start immediately: Fiverr, Upwork, local companies in Karachi.
LinkedIn presence compounds over time โ€” post consistently about your projects and learning.
Certificate 2 (Agentic AI Developer) is the natural next step โ€” building autonomous AI systems.
You are now a Gen AI Practitioner. Build, deploy, share, and keep learning. ๐Ÿš€
Reference

Appendices

Appendix A

Python Quick Reference

The Most Important Syntax at a Glance

PYTHON ยท CHEAT SHEET
# โ”€โ”€โ”€ DATA TYPES โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
s = "Hello"              # string
s = f"Name: {name}"      # f-string (always use this)
i = 42                   # integer
f = 3.14                 # float
b = True                  # boolean

# โ”€โ”€โ”€ LISTS โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
lst = [1, 2, 3]
lst.append(4)            # [1, 2, 3, 4]
lst[0]                    # 1 โ€” first item
lst[-1]                   # 4 โ€” last item
len(lst)                  # 4

# โ”€โ”€โ”€ DICTIONARIES โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
d = {"key": "value", "num": 42}
d["key"]                  # "value"
d["new"] = "added"        # add new key
d.keys() / .values() / .items()

# โ”€โ”€โ”€ CONTROL FLOW โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
if x > 0:   print("positive")
elif x < 0: print("negative")
else:        print("zero")

for item in my_list:       # iterate list
    print(item)
for i in range(10):        # 0 to 9
    print(i)

# โ”€โ”€โ”€ FUNCTIONS โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
def add(a, b=10):          # default param
    return a + b

# โ”€โ”€โ”€ ERROR HANDLING โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
try:
    result = risky_api_call()
except Exception as e:
    print(f"Error: {e}")
finally:
    cleanup()             # always runs

# โ”€โ”€โ”€ LIST COMPREHENSION โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
squares = [x**2 for x in range(10)]
evens   = [x for x in range(20) if x % 2 == 0]
Appendix B

Top 50 Prompt Templates

Copy, Adapt, Deploy โ€” Instantly Useful

Writing & Content

Blog Post
"Write a [length]-word blog post about [topic] for [audience]. Use [tone] tone. Include intro, [N] main points with subheadings, conclusion, and CTA."
LinkedIn Post
"Write a LinkedIn post about [topic/achievement] for a [role]. Max 300 words. Include 3โ€“5 hashtags. Make the first line stop-scrolling."
Professional Email
"Write a [tone] email from [sender] to [recipient] about [purpose]. Context: [background]. Desired outcome: [what you want]. Max [N] words."
Product Description
"Write a compelling product description for . Target: [audience]. Features: [list]. Tone: [persuasive]. Length: [N] words."

Analysis & Research

SWOT Analysis
"Perform a SWOT analysis of [company/idea]. Present as a structured table with 3โ€“4 points per quadrant. Be specific, not generic."
Competitor Comparison
"Compare [A] vs [B] vs [C] across these dimensions: [list]. Present as a table. Include a recommendation at the end."
Summarization
"Summarize the following [doc type] in [N] words. Focus on: key decisions made, action items, and open questions."
Research Brief
"Create a research brief on [topic]. Include: current state, key players, recent developments, major challenges, 5 questions for further research."

Coding & Technical

Code Generation
"Write a Python function that [description]. Include: type hints, docstring, error handling, and 3 usage examples."
Code Review
"Review this [language] code for: bugs, security issues, performance problems, and style. For each issue, show the fix."
Debug
"This [language] code produces [error]. Expected: [x]. Actual: [y]. Here's the code: [code]. Identify and fix the bug."
API Design
"Design a RESTful API for [application]. Specify: endpoints, HTTP methods, JSON formats, error codes, and authentication."

Education & Learning

ELI5 Explainer
"Explain [complex topic] to someone who [background]. Use an analogy from [familiar domain]. Under [N] words. Include a 1-sentence summary."
Quiz Generator
"Create a [N]-question quiz on [topic] for [level] learners. Mix: multiple choice, true/false, short answer. Include answers."
Study Plan
"Create a [N]-week study plan for [subject]. I have [hours/day] available. Current level: [beginner]. Include weekly goals and daily tasks."
Socratic Guide
"Don't give me the answer. Ask me guiding questions to help me figure out [topic] myself. I am a [level] learner."
Appendix C

AI Career Paths & Resources

Where to Go After This Book

Essential Resources

ResourceURLWhat You Get
AI By Tech Academyaibytec.comCertificate 1, 2, 3 โ€” live instructor-led courses with Muhammad Rustam
Hugging Facehuggingface.co500k+ models, datasets, free GPU via Inference API, Spaces hosting
OpenAI Platformplatform.openai.comGPT-4, DALL-E, Whisper API โ€” $5 free credit to start
Anthropic Consoleconsole.anthropic.comClaude API โ€” long context, structured outputs, free tier available
Groq Consoleconsole.groq.comFree ultra-fast Llama & Mixtral inference โ€” generous free tier
Google Colabcolab.research.google.comFree Python + GPU in browser โ€” use for all exercises in this book
Streamlit Cloudshare.streamlit.ioFree Streamlit app hosting โ€” deploy in 60 seconds from GitHub
Author's GitHubgithub.com/MuhammadRustamShomiCode examples and projects from this book and AiBytec courses
๐Ÿ† The Complete AI Career Ladder

Certificate 1 โ€” Gen AI Practitioner โœ… (This book)
Duration: 2 months  |  Fee: PKR 15,000โ€“20,000  |  Audience: Complete beginners

Certificate 2 โ€” Agentic AI Developer โ†’
Duration: 3 months  |  Fee: PKR 45,000  |  Audience: Certificate 1 graduates

Certificate 3 โ€” AI Systems Architect โ†’
Duration: 2 months  |  Fee: PKR 60,000โ€“75,000  |  Audience: Certificate 2 graduates

Full Ladder: All 3 certificates ยท 7 months ยท PKR 1,20,000โ€“1,40,000
Graduates receive the most comprehensive applied AI credential in Pakistan.

๐Ÿค–
AI BY TECH
aibytec.com  ยท  Karachi, Pakistan  ยท  Batch 2026
info@aibytec.com  ยท  github.com/MuhammadRustamShomi
"Knowledge increases by sharing, not by saving."
ยฉ 2026 AI By Tech Academy ยท Certificate 1 โ€” Gen AI Practitioner ยท Document Version 1.0