CoolFace
Apppublic

mohamed10ayman24/personal-ai-agent

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
App README

๐Ÿค– Personal AI Agent โ€” RAG-Powered Portfolio Assistant

<div align="center">

Python FastAPI LangChain Google Gemini Docker HuggingFace

"Don't just read my CV โ€” talk to it."

A production-ready AI assistant that represents me 24/7. Powered by real data from my CV, GitHub & LinkedIn. No hallucinations. No static bios. Just accurate, context-aware answers โ€” in any language.

๐ŸŒ Live Portfolio โ€ข ๐Ÿ“– API Docs โ€ข ๐Ÿš€ Live API

</div>


๐Ÿ“‹ Table of Contents


๐Ÿ“Œ Overview

Most portfolios are static pages. Mine talks back.

This project is a production-grade RAG (Retrieval-Augmented Generation) pipeline that acts as a live AI representative of my professional identity. Instead of making recruiters or collaborators dig through a PDF, they can just ask โ€” and get precise, grounded answers pulled directly from my actual data.

Built from scratch using LangChain, Google Gemini, and FastAPI, deployed on Hugging Face Spaces, and embedded live into my portfolio. Every feature was engineered with real-world reliability in mind: per-session memory, rate limiting, admin controls, and a smart fallback system so the chat never goes dark.

The goal: Replace "Here's my CV" with "Ask me anything."

โœจ Key Features

FeatureDescription
๐Ÿ” Dynamic RAG PipelineIngests CV (PDF), LinkedIn export (ZIP), and GitHub API โ€” builds a FAISS vector index automatically
๐Ÿง  Gemini-PoweredUses gemini-embedding-001 for embeddings and gemini-2.0-flash for blazing-fast responses
๐Ÿ’ฌ Multi-turn ConversationsPer-session memory โ€” each visitor gets their own isolated conversation history (auto-expires after 30 min)
โฑ๏ธ Rate LimitingIP-based protection against abuse โ€” 5 req/min by default, fully configurable via .env
๐Ÿ” Admin ControlsSecure endpoints to upload a new CV, rebuild the index, and monitor system health โ€” all without redeployment
๐Ÿ’š Health MonitoringLive status on uptime, active sessions, vectorstore state, and connected data sources
๐Ÿ”— Configurable CORSAllowlist specific domains via ALLOWED_ORIGINS โ€” production-ready for any frontend
๐Ÿ›ก๏ธ Smart FallbackIf the API is cold-starting, the frontend answers from a curated local dataset โ€” zero downtime for visitors
๐Ÿณ DockerizedSingle docker run command โ€” consistent behavior from local dev to cloud deployment
โ˜๏ธ Hugging Face SpacesLive, public, and free โ€” with Git LFS for clean binary asset management

๐Ÿ› ๏ธ Tech Stack

LayerTechnology
LanguagePython 3.9+
API FrameworkFastAPI + Uvicorn
AI OrchestrationLangChain 0.3
LLMGoogle Gemini 2.0 Flash
EmbeddingsGoogle Gemini Embedding 001
Vector DatabaseFAISS (CPU)
Session MemoryLangChain ConversationBufferWindowMemory
Data SourcesPDF (CV), GitHub REST API, LinkedIn CSV Export
InfrastructureDocker, Hugging Face Spaces, Git LFS

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                      Data Sources                         โ”‚
โ”‚   ๐Ÿ“„ CV (PDF)   โ”‚   ๐Ÿ™ GitHub API   โ”‚   ๐Ÿ’ผ LinkedIn ZIP  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                          โ”‚
                          โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚               LangChain Ingestion Pipeline                โ”‚
โ”‚    Text Splitting โ†’ Gemini Embeddings โ†’ FAISS Store       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                          โ”‚
                          โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                   FastAPI Backend                         โ”‚
โ”‚                                                          โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚  POST /ask  โ”‚  โ”‚  GET /health โ”‚  โ”‚  /admin/*      โ”‚  โ”‚
โ”‚  โ”‚ + Rate Limitโ”‚  โ”‚  + Uptime    โ”‚  โ”‚  + Auth Guard  โ”‚  โ”‚
โ”‚  โ”‚ + Session   โ”‚  โ”‚  + Sessions  โ”‚  โ”‚  + CV Upload   โ”‚  โ”‚
โ”‚  โ”‚   Memory    โ”‚  โ”‚              โ”‚  โ”‚  + Rebuild     โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                          โ”‚
                          โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                  Portfolio Frontend                        โ”‚
โ”‚            https://poortflio.netlify.app/                 โ”‚
โ”‚   Hero Section Chat Widget โ€” live, session-aware          โ”‚
โ”‚   Smart fallback when API is warming up                   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“ก API Reference

Base URL: https://mohamed10ayman24-personal-ai-agent.hf.space

GET /

Returns agent status and basic info.

json
{
  "status": "running",
  "name": "Mohamed Aymen Salem",
  "sources_loaded": 5,
  "uptime_seconds": 3600.0,
  "ready": true
}

GET /health

Health check with session and rate limit info.

json
{
  "status": "ok",
  "ready": true,
  "uptime_seconds": 3600.0,
  "active_sessions": 3,
  "rate_limit": "5 req/60s"
}

POST /ask

Ask the agent anything about Mohamed. Supports multi-turn conversations via session_id.

Request:

json
{
  "question": "What are your main technical skills?",
  "session_id": "user_abc123"
}

Response:

json
{
  "answer": "Mohamed's core skills include Python (Async, OOP), TensorFlow, FastAPI, OpenCV, DeepFace, Gemini API, and the full Microsoft Power Platform stack...",
  "sources": ["CV", "GitHub", "LinkedIn"],
  "name": "Mohamed Aymen Salem"
}

Rate limit error (429):

json
{
  "detail": "Rate limit exceeded. Try again in 45s (max 5 requests per 60s)."
}

๐Ÿ”— Try it live โ€” Swagger UI: `/docs`


๐Ÿ” Admin Endpoints

All admin endpoints require the following header:

X-Admin-Secret: your-secret-here
EndpointMethodDescription
/admin/rebuildPOSTRebuild FAISS index from all sources + reset all sessions
/admin/upload-cvPOSTUpload a new CV PDF (raw bytes) โ€” auto-backed up
/admin/statusGETFull system status: sessions, files, rate limits, uptime

Rebuild after updating your CV:

bash
curl -X POST https://mohamed10ayman24-personal-ai-agent.hf.space/admin/rebuild \
  -H "X-Admin-Secret: your-secret-here"

Upload a new CV:

bash
curl -X POST https://mohamed10ayman24-personal-ai-agent.hf.space/admin/upload-cv \
  -H "X-Admin-Secret: your-secret-here" \
  -H "Content-Type: application/pdf" \
  --data-binary @new_cv.pdf

Check system status:

bash
curl https://mohamed10ayman24-personal-ai-agent.hf.space/admin/status \
  -H "X-Admin-Secret: your-secret-here"

๐Ÿ—‚๏ธ Project Structure

personal-ai-agent/
โ”œโ”€โ”€ main.py                  # CLI entry point (interactive chat)
โ”œโ”€โ”€ api.py                   # FastAPI app โ€” all endpoints + session management
โ”œโ”€โ”€ Dockerfile               # Container config
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ .env.example             # All configurable variables
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ cv_loader.py         # PDF ingestion via pypdf
โ”‚   โ”œโ”€โ”€ github_fetcher.py    # GitHub REST API scraper
โ”‚   โ”œโ”€โ”€ linkedin_loader.py   # LinkedIn ZIP/CSV parser
โ”‚   โ””โ”€โ”€ rag_chain.py         # Gemini embeddings + LangChain RAG chain
โ””โ”€โ”€ data/
    โ”œโ”€โ”€ cv.pdf               # Your CV (tracked via Git LFS)
    โ”œโ”€โ”€ linkedin_export.zip  # LinkedIn data export (tracked via Git LFS)
    โ””โ”€โ”€ vectorstore/         # FAISS index (auto-generated, gitignored)

โš™๏ธ Local Setup

1. Clone & install

bash
git clone https://github.com/MohammedAymen/personal-ai-agent
cd personal-ai-agent
pip install -r requirements.txt

2. Configure environment

bash
cp .env.example .env

Fill in .env:

env
# Required
GOOGLE_API_KEY=AIza...
YOUR_NAME=Mohamed Aymen Salem

# GitHub (optional but recommended)
GITHUB_TOKEN=ghp_...
GITHUB_USERNAME=MohammedAymen

# File paths
CV_PDF_PATH=data/cv.pdf
LINKEDIN_CSV_PATH=data/linkedin_export.zip

# Security
ADMIN_SECRET=your-strong-secret-here

# CORS โ€” comma-separated list of allowed origins
ALLOWED_ORIGINS=https://poortflio.netlify.app,http://localhost:3000

# Rate limiting
RATE_LIMIT=5           # max requests per window per IP
RATE_LIMIT_WINDOW=60   # window in seconds

# Session memory
SESSION_TTL=1800       # seconds before inactive session expires (default: 30 min)

3. Add your data

data/cv.pdf               โ† your CV (PDF)
data/linkedin_export.zip  โ† LinkedIn data export

4. Run

bash
# Interactive CLI mode
python main.py

# API server mode
uvicorn api:app --reload --host 0.0.0.0 --port 8000
# Then open: http://localhost:8000/docs

๐Ÿณ Docker

bash
docker build -t personal-ai-agent .

docker run -p 8000:8000 \
  -e GOOGLE_API_KEY=your_key \
  -e GITHUB_TOKEN=your_github_token \
  -e GITHUB_USERNAME=MohammedAymen \
  -e YOUR_NAME="Mohamed Aymen Salem" \
  -e ADMIN_SECRET=your-secret \
  personal-ai-agent

`Dockerfile` overview:

dockerfile
FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "8000"]

โ˜๏ธ Deployment on Hugging Face Spaces

This project runs as a Docker Space on Hugging Face โ€” free, public, and always on.

Steps:

1. Git LFS โ€” track binary files:

bash
git lfs install
git lfs track "*.pdf" "*.zip"
git add .gitattributes

2. Clean history (if binaries were committed before LFS):

bash
git lfs migrate import --include="*.pdf,*.zip" --everything

3. Set secrets in Hugging Face (never commit these):

GOOGLE_API_KEY     โ†’ your Gemini API key
ADMIN_SECRET       โ†’ your admin password
GITHUB_TOKEN       โ†’ your GitHub token

4. Push & deploy:

bash
git remote add space https://huggingface.co/spaces/mohamed10ayman24/personal-ai-agent
git push space main

The Space rebuilds automatically on every push. โœ…


๐Ÿ’ก Example Questions

"What are Mohamed's main technical skills?"
"Tell me about the Blockchain Voting System project"
"Does he have experience with FastAPI or async Python?"
"What is his educational background?"
"Has he worked with computer vision before?"
"What certifications does he have?"
"ู…ุง ู‡ูŠ ู…ุดุงุฑูŠุนู‡ ููŠ ู…ุฌุงู„ ุงู„ุฐูƒุงุก ุงู„ุงุตุทู†ุงุนูŠุŸ"
"ู‡ู„ ู„ุฏูŠู‡ ุฎุจุฑุฉ ููŠ Power PlatformุŸ"

๐ŸŒ Live Integration

This API is the brain behind the AI Chat Widget embedded in the hero section of my portfolio. Every visitor gets their own isolated conversation โ€” powered by real data, not a script.

๐Ÿ”— [https://poortflio.netlify.app/](https://poortflio.netlify.app/)

How it works for visitors:

  1. 1.Page loads โ†’ a unique session_id is generated in the browser
  2. 2.Visitor types a question โ†’ sent to the Hugging Face API with their session ID
  3. 3.The API retrieves relevant context from the vector store and responds with Gemini
  4. 4.Conversation history is maintained per session for natural follow-up questions
  5. 5.If the API is cold-starting โ†’ smart fallback answers from local curated data

๐Ÿ‘จโ€๐Ÿ’ป Author

Mohamed Aymen Salem AI Engineer & Developer โ€” Machine Learning ยท Computer Vision ยท NLP ๐Ÿ“ Port Said, Egypt

![GitHub](https://github.com/MohammedAymen) ![LinkedIn](https://linkedin.com/in/mohamed-aymen-750236225) ![Portfolio](https://poortflio.netlify.app/)


Built with โค๏ธ ยท Powered by Gemini ยท Deployed on Hugging Face