Team Ai
Apppublic

Krishna-11Analyst/LLM-code-deployments

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
README.md276 linesDownload Raw Back to root
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**