Skip to content
All projects

Marketing Campaign Application

Flask API that turns a one-line ad campaign brief into a GPT-4o campaign plan delivered as Excel.

Role
Backend Developer (Intern)
Timeframe
May 2024 - July 2024
Stack
  • Python
  • Flask
  • OpenAI Assistants API
  • GPT-4o
  • pandas
  • openpyxl

Problem

Users needed to type a short campaign brief (ad channel, age range, countries, interests) and get back a complete campaign plan they could open in Excel. The plan had to follow a written Facebook and Instagram ads playbook, not generic LLM advice. It also had to come back in the same JSON shape every time so code could turn it into a spreadsheet. The playbooks changed often, so updating them could not require a code change.

Architecture

A client POSTs a brief to a Flask REST API. A service class built on the OpenAI Python SDK opens a thread on an OpenAI Assistant (GPT-4o with file search) attached to a vector store of channel instruction files, then polls the run until it completes. Flask parses the plan JSON and uses pandas and openpyxl to write a workbook saved under a UUID, then returns a download URL. Admin endpoints rebuild the vector store and assistant, and every step writes to info and error log files.

  1. Client POSTs a campaign brief to /api/chat
  2. GPT-4o assistant searches the channel playbooks
  3. Service polls the run until the plan JSON is ready
  4. Flask builds the Excel file, logs it, returns a URL
  5. Admin upload rebuilds the vector store and assistant

What I built

  • Built a Flask API with 5 endpoints that turns a plain-English brief into a downloadable Excel campaign plan, using the OpenAI Assistants API (GPT-4o, file search, vector store).
  • Designed a two-level prompt chain: a master prompt fixes the top-level keys and maps each channel to its instruction file, and the Facebook/Instagram file (plus a separate targeting file) defines its sections and exact JSON keys. Adding a channel means adding a file, not code.
  • Wrote the JSON-to-Excel converter with pandas json_normalize and openpyxl: nested ad examples go to their own sheet, targeting fields are flattened into columns, and list fields become bullet text inside cells.
  • Added admin endpoints that swap the knowledge base without a redeploy: upload a zip of playbooks (rejected unless every file inside is .txt), delete and recreate the vector store and assistant, and report which IDs are active.
  • Parsed model output as data, not code: strip markdown fences, then ast.literal_eval, and return a JSON error if parsing fails.
  • Managed generated files: UUID file names, a download route, and cleanup that deletes workbooks older than one hour (checked at most every 10 minutes).

Results

  • A one-sentence brief returns a download link to a workbook with a Summary sheet (context, objective, placements, creative recommendations, best practices) and an Examples sheet of sample ads with proposed targeting.
  • Whoever owns the content can change the channel playbooks and the master prompt through the API, with no code edit or redeploy.
  • Delivered as a self-contained package: the API, the assistant service class, structured info and error logs, and a README with curl and Postman examples for each endpoint.