Krishna-11Analyst/LLM-code-deployments
0
1---2title: LLM Code Deployments3emoji: ๐4colorFrom: blue5colorTo: green6sdk: docker7app_file: app/main.py8pinned: false9---10 11# LLM Code Deployment System12 13This is an automated system for building and deploying web applications based on natural language briefs...14# ๐ LLM Code Deployment System15 16Production-ready automated web application generator for **IIT Madras TDS Project-1**.17 18**Live API:** `https://Krishna-11Analyst-llm-deployment-final.hf.space`19 20---21 22## โจ Features23 24- โ
**Correct API Endpoint:** `/api-endpoint` (matches IIT-M specification)25- โ
**Multi-Round Support:** Handles Round 1 (create) and Round 2+ (update)26- โ
**OpenAI GPT-4:** Generates complete, working web applications27- โ
**Automatic GitHub Integration:** Creates repositories and enables Pages28- โ
**Duplicate Detection:** Uses nonce to prevent reprocessing29- โ
**File Attachments:** Supports CSV, images, and other data files30- โ
**Evaluation Callback:** Automatic notification with retry logic31- โ
**Background Processing:** Non-blocking with immediate HTTP 200 response32 33---34 35## ๐ก API Usage36 37### **Endpoint**38```39POST /api-endpoint40```41 42### **Request Format**43```json44{45 "email": "student@example.com",46 "secret": "your-secret",47 "task": "unique-task-id",48 "round": 1,49 "nonce": "unique-nonce",50 "brief": "Create a Bootstrap page with weather display",51 "checks": [52 "Repo has MIT license",53 "README.md is professional",54 "Page displays weather data"55 ],56 "evaluation_url": "https://evaluation-server.com/notify",57 "attachments": [58 {59 "name": "data.csv",60 "url": "data:text/csv;base64,..."61 }62 ]63}64```65 66### **Response (Immediate)**67```json68{69 "status": "accepted",70 "note": "processing round 1 started"71}72```73 74### **Background Process**75After returning HTTP 200, the system:761. Generates code using OpenAI GPT-4 (~30-60 seconds)772. Creates/updates GitHub repository (~5-10 seconds)783. Enables GitHub Pages (~10-20 seconds)794. Sends evaluation callback with repo details80 81---82 83## ๐ ๏ธ Local Development84 85### **1. Setup**86```bash87# Clone or copy project88cd llm-deployment-final89 90# Create virtual environment91python -m venv venv92 93# Activate (Windows)94venv\Scripts\activate95 96# Activate (Mac/Linux)97source venv/bin/activate98 99# Install dependencies100pip install -r requirements.txt101```102 103### **2. Configure Environment**104Create `.env` file with your credentials:105```env106GITHUB_TOKEN=your_github_token107GITHUB_USERNAME=your_username108OPENAI_API_KEY=your_openai_key109USER_SECRET=your_secret110```111 112### **3. Run Server**113```bash114uvicorn app.main:app --reload115```116 117API will be available at: `http://localhost:8000`118 119### **4. Test Endpoint**120```bash121curl -X POST http://localhost:8000/api-endpoint \122 -H "Content-Type: application/json" \123 -d '{124 "email": "test@example.com",125 "secret": "your_secret",126 "task": "test-001",127 "round": 1,128 "nonce": "test-nonce-001",129 "brief": "Create a simple hello world page",130 "checks": ["Has hello world text"],131 "evaluation_url": "https://httpbin.org/post",132 "attachments": []133 }'134```135 136---137 138## ๐ Deployment (Hugging Face Spaces)139 140### **1. Create Space**141- Go to: https://huggingface.co/new-space142- Name: `llm-deployment-final`143- SDK: **Docker**144- Hardware: **CPU Basic** (free tier)145 146### **2. Push Code**147```bash148git init149git add .150git commit -m "Initial deployment"151git remote add space https://huggingface.co/spaces/Krishna-11Analyst/llm-deployment-final152git push space main153```154 155### **3. Configure Secrets**156In Space Settings โ Repository secrets, add:157- `GITHUB_TOKEN`158- `GITHUB_USERNAME`159- `OPENAI_API_KEY`160- `USER_SECRET`161 162### **4. Wait for Build**163Space will build (~5-10 minutes) and show "Running" status when ready.164 165---166 167## ๐ Architecture168```169FastAPI API170 โ171โโโโโโโโโโโโโโโโโโโโโโโ172โ /api-endpoint โ โ Receives JSON POST173โ - Validates secret โ174โ - Returns HTTP 200 โ175โ - Starts background โ176โโโโโโโโโโโโโโโโโโโโโโโ177 โ178โโโโโโโโโโโโโโโโโโโโโโโ179โ Background Process โ180โ 1. OpenAI GPT-4 โ โ Generate code181โ 2. GitHub API โ โ Create repo182โ 3. Enable Pages โ โ Deploy site183โ 4. Evaluation POST โ โ Notify server184โโโโโโโโโโโโโโโโโโโโโโโ185```186 187---188 189## ๐ง Technology Stack190 191- **FastAPI** - Web framework192- **OpenAI GPT-4** - Code generation193- **PyGithub** - GitHub API integration194- **HTTPX** - HTTP client for callbacks195- **Docker** - Containerized deployment196- **Hugging Face Spaces** - Hosting platform197 198---199 200## ๐ Project Structure201```202llm-deployment-final/203โโโ .env # Credentials (DO NOT commit!)204โโโ .gitignore # Git ignore rules205โโโ .dockerignore # Docker ignore rules206โโโ Dockerfile # Docker configuration207โโโ README.md # This file208โโโ requirements.txt # Python dependencies209โโโ runtime.txt # Python version210โโโ test_github.py # Local testing script211โโโ app/212 โโโ __init__.py # Package init213 โโโ main.py # FastAPI app & endpoints214 โโโ llm_generator.py # OpenAI code generation215 โโโ github_utils.py # GitHub operations216 โโโ notify.py # Evaluation callbacks217 โโโ signature.py # (Empty placeholder)218```219 220---221 222## โ
Submission Information223 224| Field | Value |225|-------|-------|226| **API Endpoint** | `https://Krishna-11Analyst-llm-deployment-final.hf.space` |227| **Secret** | `student_secret_123` |228| **GitHub Source Repo** | `https://github.com/23f2001849/tds-project-1-main` |229| **Student Email** | `23f2001849@ds.study.iitm.ac.in` |230 231---232 233## ๐ Security Notes234 235### **Post-Submission Actions**236Within 24 hours of submission, regenerate exposed credentials:237 2381. **GitHub Token:**239 - Visit: https://github.com/settings/tokens240 - Delete old token241 - Create new token with `repo` and `workflow` scopes242 - Update Hugging Face Space secret243 2442. **OpenAI Key:**245 - Visit: https://platform.openai.com/api-keys246 - Revoke old key247 - Create new key248 - Update Hugging Face Space secret249 250---251 252## ๐ License253 254MIT License255 256---257 258## ๐จโ๐ป Author259 260**Student ID:** 23f2001849 261**Email:** 23f2001849@ds.study.iitm.ac.in 262**Course:** IIT Madras - Tools in Data Science - Project 1 263**Date:** October 2025264 265---266 267## ๐ Acknowledgments268 269- **OpenAI** for GPT-4 API270- **GitHub** for repository hosting and Pages271- **Hugging Face** for Spaces deployment platform272- **IIT Madras** for the learning opportunity273 274---275 276**Built with โค๏ธ for IIT-M TDS Project-1**