Sunday, March 23, 2025

Crea tu primer sitio web interactivo impulsado por IA generativa con el modelo LLaMA de Meta

¡Hola amigas y amigos! 👋

En este tutorial, vas a crear una página web súper sencilla donde las personas puedan escribir una pregunta y recibir una respuesta de una IA — ¡igual que con ChatGPT! Pero aquí usarás el modelo LLaMA de Meta (un modelo de IA de código abierto) a través de Hugging Face.

Vas a aprender a:

  • ✅ Usar un modelo de IA
  • ✅ Crear una página web básica
  • ✅ Conectar todo con código en Python

🧠 ¿Qué herramientas vamos a usar?

Antes de comenzar a escribir código, conozcamos las herramientas:

🟣 Hugging Face

Imagina una biblioteca gigante de modelos de IA poderosos (como LLaMA, GPT, etc.) que puedes usar en tus proyectos. Es como el Netflix de los modelos de IA — ¡solo inicia sesión, elige uno y listo!

🟠 Flask (Python)

Es un programa ligero que convierte tu código en Python en una pequeña página web. Es como el cerebro que está detrás de escena — recibe la pregunta del usuario, se la pasa a la IA, y devuelve la respuesta.


✅ Tutorial paso a paso

🔧 Paso 1: Abre Google Colab

Ve a Google Colab y abre un nuevo notebook.

📦 Paso 2: Instala las herramientas necesarias

!pip install flask flask-ngrok transformers torch pyngrok

🔐 Paso 3: Inicia sesión en Hugging Face

  1. Visita https://huggingface.co
  2. Inicia sesión → Ve a Settings > Access Tokens
  3. Copia tu token y pégalo aquí:
from huggingface_hub import login
HUGGING_FACE_KEY = "pega-tu-token-aquí"
login(HUGGING_FACE_KEY)

🤖 Paso 4: Carga el modelo LLaMA de Meta

from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

model_name = "meta-llama/Llama-3.2-1B"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

🧠 Paso 5: Construyamos el backend (el cerebro del sitio web)

¿Qué es el backend?
Es como el chef en un restaurante. La persona hace un pedido (una pregunta), y el backend prepara la respuesta usando IA.

from flask import Flask, request, jsonify
from flask_ngrok import run_with_ngrok

app = Flask(__name__)
run_with_ngrok(app)

@app.route("/ask", methods=["POST"])
def ask():
    prompt = request.json.get("prompt", "")
    inputs = tokenizer(prompt, return_tensors="pt")
    outputs = model.generate(inputs["input_ids"], max_length=100)
    response = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return jsonify({"response": response})

🌐 Paso 6: Crea la página web (frontend)

Ahora vamos a construir la parte que las personas ven e interactúan — el frontend.

%%writefile index.html
<!DOCTYPE html>
<html>
<head><title>Pregúntale a la IA</title></head>
<body>
  <h2>Pregúntale a la IA</h2>
  <textarea id="prompt" rows="4" cols="50" placeholder="Escribe tu pregunta aquí..."></textarea><br>
  <button onclick="askAI()">Preguntar</button>
  <p><strong>Respuesta:</strong> <span id="response"></span></p>

  <script>
    async function askAI() {
      const prompt = document.getElementById("prompt").value;
      const res = await fetch("/ask", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({ prompt: prompt })
      });
      const data = await res.json();
      document.getElementById("response").innerText = data.response;
    }
  </script>
</body>
</html>

🧩 Paso 7: Conecta todo y ejecuta la app

from flask import send_from_directory

@app.route('/')
def serve_frontend():
    return send_from_directory('.', 'index.html')

app.run()

Vas a recibir un enlace como este: https://xxxxx.ngrok.io
¡Haz clic y... 🎉 tu sitio web con IA está EN VIVO!


🏁 ¡Misión cumplida!

Acabas de construir:

  • Un asistente de IA funcionando con el modelo LLaMA de Meta
  • Una página web personalizada
  • Un backend en Python que conecta todo

¡Ya estás programando con modelos de IA reales! Bienvenida/o al mundo del desarrollo con inteligencia artificial 💻🤖🧠

Build Your First Interactive Generative AI Website with Meta’s LLaMA Model

Hi friends! 👋

In this tutorial, you’ll create a super simple website where users can type a question and get a response from an AI — just like ChatGPT, but using Meta’s LLaMA model (an open-source AI model) through Hugging Face.

You’ll learn how to:

  • ✅ Use an AI model
  • ✅ Create a basic web page
  • ✅ Connect it all with Python code

🧠 What Are These Tools?

Before we start coding, let’s understand the tools we’re using:

🟣 Hugging Face

Think of this as a giant library of powerful AI models (like LLaMA, GPT, etc.) that you can use in your own apps. It’s like the Netflix of AI models — just log in, choose a model, and go!

🟠 Flask (Python)

This is a mini program that turns your Python code into something that can be used on a website. It’s like the brain behind the scenes — it listens to the user’s question, sends it to the AI, and gives back the answer.


✅ Step-by-Step Tutorial

🔧 Step 1: Open Google Colab

Go to Google Colab and open a new notebook.

📦 Step 2: Install the Tools We Need

!pip install flask flask-ngrok transformers torch pyngrok

🔐 Step 3: Log Into Hugging Face

  1. Go to https://huggingface.co
  2. Sign up/log in → Go to Settings > Access Tokens
  3. Copy your token and paste it into this code:
from huggingface_hub import login
HUGGING_FACE_KEY = "paste-your-key-here"
login(HUGGING_FACE_KEY)

🤖 Step 4: Load Meta’s LLaMA Model

from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

model_name = "meta-llama/Llama-3.2-1B"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

🧠 Step 5: Let’s Build the Backend (The Brain Behind the Website)

What’s the backend? It’s like the chef in a restaurant. The user places an order (asks a question), and the backend prepares the response using AI.

from flask import Flask, request, jsonify
from flask_ngrok import run_with_ngrok

app = Flask(__name__)
run_with_ngrok(app)

@app.route("/ask", methods=["POST"])
def ask():
    prompt = request.json.get("prompt", "")
    inputs = tokenizer(prompt, return_tensors="pt")
    outputs = model.generate(inputs["input_ids"], max_length=100)
    response = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return jsonify({"response": response})

🌐 Step 6: Create the Web Page (Frontend)

Now, let’s build the frontend — the part that people see and interact with.

%%writefile index.html
<!DOCTYPE html>
<html>
<head><title>Ask AI</title></head>
<body>
  <h2>Ask the AI</h2>
  <textarea id="prompt" rows="4" cols="50" placeholder="Type your question here..."></textarea><br>
  <button onclick="askAI()">Ask</button>
  <p><strong>Response:</strong> <span id="response"></span></p>

  <script>
    async function askAI() {
      const prompt = document.getElementById("prompt").value;
      const res = await fetch("/ask", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({ prompt: prompt })
      });
      const data = await res.json();
      document.getElementById("response").innerText = data.response;
    }
  </script>
</body>
</html>

🧩 Step 7: Connect It All and Run the App

from flask import send_from_directory

@app.route('/')
def serve_frontend():
    return send_from_directory('.', 'index.html')

app.run()

You'll get a link like this: https://xxxxx.ngrok.io
Click it and... 🎉 Your AI-powered website is LIVE!


🏁 Final Words

You just built:

  • A working AI assistant using Meta's LLaMA model
  • A custom web page
  • A backend in Python to power it

You're officially coding with real AI models. That’s amazing. Welcome to the world of AI development!

Friday, March 21, 2025

Mini-Course: Start Gig Work with Generative AI

I'm excited to share a brand-new mini-course designed to help you start your freelance journey using the power of Generative AI! 💡🤖

This course walks you through how to:

  • ✅ Identify the best freelance gigs based on your skills and cultural background
  • ✅ Use AI tools to find opportunities that help you earn more & work smarter
  • ✅ Take actionable steps to launch your freelance business 🚀

Whether you're just starting out or looking to level up your freelance game, this course gives you the tips, tools, and mindset to succeed.

🔵 Check it out here: Watch Now

💬 Let’s talk! Where are you in your freelancing journey? Will you be using any of these strategies in your business? Have you tried using Generative AI to support your work?

👇 Drop your thoughts in the comments — I’d love to hear from you!

#Freelancing #GigWork #GenerativeAI #AIforWork #WorkSmarter #FreelancerTips

Sunday, March 02, 2025

Navigating the Gig Economy with AI: Building a Smart Career Guidance System

By: Aishwarya Abbimutt Nagendra Kumar (Civic AI Lab Research Assistant)

Navigating the Gig Economy with AI: Building a Smart Career Guidance System

In today’s fast-paced gig economy, freelancers and gig workers often face challenges in navigating career growth. The lack of structured guidance makes it difficult to identify in-demand skills, map transferable expertise to emerging roles, or even decide the next best career move. With a surge in remote work and technology-driven industries, the need for personalized career advice has never been more critical.

To address this problem, I embarked on a project to build an AI-driven Skill Recommendation System that empowers gig workers by providing actionable career insights. By leveraging cutting-edge generative AI and retrieval-augmented generation (RAG) techniques, this system generates tailored recommendations based on user profiles, market trends, and income data. Here’s how I approached this exciting challenge.

Understanding the Problem

Gig workers often lack access to structured career counseling or platforms that provide:

  • A clear understanding of in-demand skills in the current market.
  • Insight into how their existing skills can translate into better-paying roles.
  • Recommendations for upskilling or career switches based on industry trends.

While some online platforms provide generalized advice, there is a gap in delivering personalized and data-driven recommendations tailored to individual profiles and aspirations.

The Solution

The system I created combines two smart components to help gig workers make better career decisions:

  1. Market Insights Engine: This part of the system looks up and gathers important information about the job market, like which skills are in demand and what career paths are trending.
  2. Personalized Career Advisor: This part takes a user’s skills and goals and suggests the best career paths or skills to learn to move forward in their career.

Together, these components work smoothly to analyze the user's information and provide clear, practical advice through an easy-to-use interface.

The Pipeline

1. Retrieval-Augmented Generation (RAG) Pipeline

The RAG pipeline is the backbone of the system, enabling contextual retrieval of market data and generating insightful responses. Here’s how it works:

  • Document Processing: The pipeline processes large datasets of market trends and job requirements, breaking them into manageable chunks for analysis.
  • Embeddings and Semantic Search: Using an embedding model, the pipeline converts text into vector representations, which are stored in ChromaDB, a high-performance vector database. This allows for efficient retrieval of relevant data based on user queries.
  • Response Generation: Leveraging a generative LLM (I have used the Llama 3.2 model), the pipeline synthesizes a comprehensive response by combining retrieved information with generative capabilities.

This integration of retrieval and generation ensures that the system provides career advice backed by real-time market data, enhancing its relevance and precision.

2. Recommender Pipeline

The recommender pipeline delivers personalized career advice through four main tasks:

  • Skill Mapping: Matches the user’s existing skills with in-demand job roles.
  • Income Comparison: Provides a comparative analysis of income potential across suggested roles.
  • Career Recommendation: Based on the skill mapping and income comparison, the best career path is chosen.
  • Upskilling Recommendations: Suggests specific skills to learn, complete with links to curated resources for training.

The Language Model (LLM) pipeline is at the heart of the recommendation system, designed to generate career guidance and skill suggestions. For this purpose, we utilize the Llama 3.2 Instruct-tuned model, known for its capability to generate nuanced and contextually relevant outputs.

How It Works

The LLM pipeline begins by collecting user input, such as their skills and current income. This data is dynamically integrated into carefully crafted prompts. Significant effort has been invested in prompt engineering to ensure that the LLM comprehends the user’s context and provides insightful recommendations. We also use chain-of-thought prompting, which encourages the model to reason step-by-step, resulting in more logical and detailed outputs.

Model Access and Integration

The Llama 3.2 model is accessed via the Hugging Face API. After obtaining permissions from both Meta (the model's creator) and Hugging Face, an API token was securely stored in a .env file. This token is used to integrate the model into the pipeline, ensuring seamless access.

Integration of LLM and RAG Pipelines

The integration of the LLM and RAG pipelines ensures that the system provides recommendations informed by both user-specific data and market-driven insights. The integration workflow is implemented as follows:

  1. The RAG pipeline retrieves relevant contextual information and stores it in a JSON file.
  2. This file is dynamically referenced in the LLM pipeline’s prompts.
  3. The combined output is presented to the user via a user-friendly web interface built using Gradio.

Gradio Interface

The Gradio interface allows users to input their skills and income and receive actionable career advice.

Future Work

  • Evaluation Metrics: Robust evaluation methodologies will be developed to quantify the effectiveness of the recommendations.
  • Fine-tuning the LLM: Future iterations will involve fine-tuning the LLM on real gig worker profiles for enhanced personalization.
  • Expanded Data Sources: Incorporating more diverse and comprehensive datasets will improve the accuracy of recommendations.

Conclusion

This project demonstrates the transformative potential of generative AI in career guidance. By addressing the unique challenges faced by gig workers, this system provides a valuable resource for upskilling, career switching, and achieving financial growth.

Stay tuned for updates and enhancements! Check out the GitHub repository here:

GitHub Repository

Thursday, February 06, 2025

🚀 Ethical AI at Akamai 🤖

I was truly honored to give a lightning talk on Ethical AI at Akamai Technologies in collaboration with The Mass Technology Leadership Council🔥—New England’s premier network for tech companies driving innovation & global impact 🌎.

Opening Words from Akamai CTO

🎤 We kicked off with Opening Words from Robert Blumofe, CTO of Akamai, who gave a powerful talk on why AI ethics is fundamentally different from traditional algorithms. Unlike past computing systems, today’s AI can make decisions humans used to make 🤯, meaning we must get AI ethics right from the start!

My Talk: Ethical AI for All Stakeholders

🧠 I then had the opportunity to present, where I shared how ethical AI requires considering ALL stakeholders—from the data labelers 🏗️, to the engineers designing the models 🖥️, to the end users 📲, and the companies integrating AI 💡. Only by taking a holistic approach can we ensure AI is fair, sustainable, and beneficial for everyone!

Generative AI for Ethical Workflows

💡 I also showcased generative AI tools my research lab has created to support AI workers, ensuring a win-win ecosystem where AI is built more ethically from the ground up. (Slides attached below! ⬇️)

Women in AI: Liz Graham's Inspiring Leadership

✨ Next up, Liz Graham, CEO of Ada IQ, shared how her company, founded by Northeastern University professors, is using generative AI to support the entire product lifecycle. Seeing a woman entrepreneur and tech leader 🔥🚀 at the forefront of AI innovation was incredibly inspiring! 💪 It reinforced why diverse leadership is key in shaping the future of AI.

AI Literacy & The Kendall Project

🤝 I also loved meeting Brendan McSheffrey from The Kendall Project, which is working to educate companies across New England on how to integrate AI into their workflows. 🎓💼 AI literacy is crucial to making AI accessible and driving responsible innovation.

Gratitude & Next Steps

🙏 A huge thank you to Nayla Daly for the invitation and to Michelle Gardner from Khoury College of Computer Sciences for fostering faculty-industry collaborations 🤝.

💭 Looking forward to more collaborations and conversations on how we can build AI that is ethical, inclusive, and transformative! 🚀

Monday, December 30, 2024

Using AI for Peace-Building with IFIT

On the last Monday of the year, I had the privilege of collaborating with my lab to deliver a mini-course on prompt engineering for the Institute for Integrated Transitions (IFIT). IFIT’s remarkable work supports fragile and conflict-affected states in achieving inclusive negotiations and sustainable transitions out of war, crisis, or authoritarianism. From their role in the Colombia-FARC peace-building process to their ongoing efforts in Sudan, their impact is both inspiring and transformative.

Course Highlights

Our mini-course focused on equipping IFIT with tools to use generative AI in their peace-building initiatives. Specifically, we explored how to design surveys that can illuminate regional polarization dynamics in Sudan. Here’s what we covered:

  • Creating open-ended and multiple-choice survey questions to understand the effects of tribal and ethnic affiliations on polarization.
  • Using AI to iterate and refine survey questions for clarity and cultural sensitivity.
  • Tailoring surveys for different populations and translating them into local languages using AI tools.
  • Employing AI for A/B testing to optimize survey effectiveness.

A Team Effort

This course was a true team effort. A big thank you to Jesse Nava, our program manager, and Rafael Morales from UNAM. Their extensive experience creating surveys for marginalized communities and working with gang-affiliated networks added invaluable depth and expertise to the course.

Explore More

If you’re interested in learning more about how generative AI can support peace-building initiatives, we’ve made our slides available for further exploration. We hope they inspire new ways to leverage technology for positive change.

#AIforGood #PeaceBuilding #GenerativeAI #PromptEngineering

Thursday, December 12, 2024

How to Summon AI Magic with Python: A Fun Guide to Generative AI APIs

Hey there, tech explorers! Ever wanted to whip up some magical AI-generated text, like having robot Shakespeares at your fingertips? Well, today’s your lucky day! We’re here to break down a piece of Python code that lets you chat with a fancy AI model and generate text like pros. No PhDs required, we promise.

First Things First: The Toolbox

Before we can talk to the AI, we need to grab some tools. Think of it like prepping for a camping trip—you need a tent (the model) and some snacks (the tokenizer).

        
pip install transformers
        
    

This command installs the Transformers library, which is like the Swiss Army knife of AI text generation. It’s brought to you by Hugging Face (no, not the emoji—it’s a company!).

Step 1: Unlock the AI Vault

We’ll need to log in to Hugging Face to get access to their cool models. Think of it as showing your library card before borrowing books.

        
from huggingface_hub import login
login("YOUR HUGGING FACE LOGIN")
        
    

Replace "YOUR HUGGING FACE LOGIN" with your actual login token. It’s how we tell Hugging Face, "Hey, it’s us—let us in!"

Step 2: Meet the Model

Now we load the AI brain. In our case, we’re using Meta’s Llama 3.2, which sounds like a cool llama astronaut but is actually an advanced AI model.

        
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

model_name = "meta-llama/Llama-3.2-1B"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto")
        
    

- Tokenizer: This breaks down your input text into AI-readable gibberish. - Model: The big brain that generates the text.

Step 3: Give It Something to Work With

Now comes the fun part: asking the AI a question or giving it a task.

        
input_text = "Explain the concept of artificial intelligence in simple terms."
inputs = tokenizer(input_text, return_tensors="pt")
        
    

- input_text: This is your prompt—what you’re asking the AI to do. - tokenizer: It converts your input into numbers the model can understand.

Step 4: Let the Magic Happen

Here’s where the AI flexes its muscles and generates text based on your prompt.

        
outputs = model.generate(
    inputs["input_ids"].to("cuda"), 
    max_length=100, 
    num_return_sequences=1, 
    temperature=0.7, 
    top_p=0.9, 
)
        
    

- inputs["input_ids"].to("cuda"): Sends the work to your GPU if you’ve got one. - max_length: How long you want the AI’s response to be. - temperature: Controls creativity. - top_p: Controls how "risky" the word choices are.

Step 5: Ta-Da! Your Answer

Finally, we take the AI’s response and turn it back into human language.

        
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(generated_text)
        
    

skip_special_tokens=True tells the AI, "Please don’t include random weird symbols in your answer."

So, What’s Happening Under the Hood?

Here’s a quick analogy for how this works:

  • We give the AI a prompt (our input text).
  • The tokenizer translates our words into numbers.
  • The model (our AI brain) uses these numbers to predict the best possible next words.
  • It spits out a response, which the tokenizer translates back into words.

It’s like ordering a coffee at Starbucks: we place the order, the barista makes it, and voilà—our coffee is ready!

Why Should We Care?

Generative AI APIs like this are the backbone of chatbots, creative writing tools, and even marketing copy generators. Whether we’re developers, writers, or just curious, playing with this code is a great way to dip our toes into the AI ocean.

Ready to Try It?

Copy the code, tweak the prompt, and see what kind of magic we can summon. Who knows? We might create the next big AI-powered masterpiece—or at least have some fun along the way.

Now go forth and generate! 🎉