unknown
commited on
Commit
·
ba949f7
0
Parent(s):
Initial commit: PipelineForge MCP v1.0 - MCP 1st Birthday Hackathon
Browse files- .gitignore +54 -0
- README.md +173 -0
- app.py +552 -0
- rag_templates_minimal.py +184 -0
- requirements.txt +26 -0
.gitignore
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Environment variables (NEVER commit API keys!)
|
| 2 |
+
.env
|
| 3 |
+
*.env
|
| 4 |
+
|
| 5 |
+
# Python
|
| 6 |
+
__pycache__/
|
| 7 |
+
*.py[cod]
|
| 8 |
+
*$py.class
|
| 9 |
+
*.so
|
| 10 |
+
.Python
|
| 11 |
+
build/
|
| 12 |
+
develop-eggs/
|
| 13 |
+
dist/
|
| 14 |
+
downloads/
|
| 15 |
+
eggs/
|
| 16 |
+
.eggs/
|
| 17 |
+
lib/
|
| 18 |
+
lib64/
|
| 19 |
+
parts/
|
| 20 |
+
sdist/
|
| 21 |
+
var/
|
| 22 |
+
wheels/
|
| 23 |
+
*.egg-info/
|
| 24 |
+
.installed.cfg
|
| 25 |
+
*.egg
|
| 26 |
+
|
| 27 |
+
# ChromaDB / Vector Store
|
| 28 |
+
chroma_db/
|
| 29 |
+
test_chroma_db/
|
| 30 |
+
test_chroma_simple/
|
| 31 |
+
test_minimal/
|
| 32 |
+
*.db
|
| 33 |
+
|
| 34 |
+
# Audio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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: PipelineForge MCP
|
| 3 |
+
emoji: 🔧
|
| 4 |
+
colorFrom: purple
|
| 5 |
+
colorTo: pink
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 5.9.1
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: true
|
| 10 |
+
tags:
|
| 11 |
+
- mcp-in-action-track-enterprise
|
| 12 |
+
- aws-glue
|
| 13 |
+
- etl
|
| 14 |
+
- data-engineering
|
| 15 |
+
- rag
|
| 16 |
+
- chromadb
|
| 17 |
+
license: mit
|
| 18 |
+
---
|
| 19 |
+
|
| 20 |
+
# 🔧 PipelineForge MCP
|
| 21 |
+
|
| 22 |
+
**AWS Glue ETL Optimizer with AI-Powered Workflow**
|
| 23 |
+
|
| 24 |
+
Transform your ETL development with AI! PipelineForge MCP is an intelligent MCP (Model Context Protocol) server that automates AWS Glue ETL pipeline creation from screenshots to production-ready code.
|
| 25 |
+
|
| 26 |
+
## 🏆 MCP 1st Birthday Hackathon Submission
|
| 27 |
+
|
| 28 |
+
**Track:** MCP in Action - Enterprise Category
|
| 29 |
+
**Tag:** `mcp-in-action-track-enterprise`
|
| 30 |
+
|
| 31 |
+
## ✨ Features
|
| 32 |
+
|
| 33 |
+
### 6 Integrated MCP Tools
|
| 34 |
+
|
| 35 |
+
1. **🔍 Screenshot Analysis** - Extract ETL requirements from AWS console images using Claude Vision
|
| 36 |
+
2. **🚀 Script Generation** - Generate optimized PySpark scripts with AWS Glue best practices
|
| 37 |
+
3. **💵 Cost Simulation** - Calculate AWS Glue job costs before deployment
|
| 38 |
+
4. **🏭 CDK Infrastructure** - Generate AWS CDK Python code for complete deployment
|
| 39 |
+
5. **🎤 Voice Summary** - ElevenLabs TTS narration of your pipeline
|
| 40 |
+
6. **📚 Template Library** - RAG-powered similarity search with 5 ETL templates
|
| 41 |
+
|
| 42 |
+
### 🎯 Key Technologies
|
| 43 |
+
|
| 44 |
+
- **🧠 Claude AI (Anthropic)**: Vision and text generation
|
| 45 |
+
- **🔍 RAG Search**: ChromaDB + SentenceTransformers for template matching
|
| 46 |
+
- **🎙️ ElevenLabs**: Text-to-speech for pipeline summaries
|
| 47 |
+
- **⚡ Modal**: Serverless cost simulation
|
| 48 |
+
- **🎨 Gradio 5+**: Modern, colorful UI with automatic data flow
|
| 49 |
+
|
| 50 |
+
## 🚀 How It Works
|
| 51 |
+
|
| 52 |
+
**Automatic Workflow** - Each step uses data from previous steps automatically:
|
| 53 |
+
|
| 54 |
+
1. **Upload Screenshot** → Extract requirements
|
| 55 |
+
2. **Generate Script** → AI creates PySpark code
|
| 56 |
+
3. **Simulate Cost** → Calculate AWS expenses
|
| 57 |
+
4. **Generate CDK** → Infrastructure as code
|
| 58 |
+
5. **Voice Summary** → Audio explanation
|
| 59 |
+
6. **Find Templates** → Similar ETL patterns
|
| 60 |
+
|
| 61 |
+
No copy/paste needed - data flows automatically!
|
| 62 |
+
|
| 63 |
+
## 💻 Local Setup
|
| 64 |
+
|
| 65 |
+
```bash
|
| 66 |
+
# Clone repository
|
| 67 |
+
git clone <repo-url>
|
| 68 |
+
cd pipelineforge-mcp
|
| 69 |
+
|
| 70 |
+
# Install dependencies
|
| 71 |
+
pip install -r requirements.txt
|
| 72 |
+
|
| 73 |
+
# Set environment variables
|
| 74 |
+
# ANTHROPIC_API_KEY=your_key
|
| 75 |
+
# ELEVENLABS_API_KEY=your_key
|
| 76 |
+
|
| 77 |
+
# Run app
|
| 78 |
+
python app.py
|
| 79 |
+
```
|
| 80 |
+
|
| 81 |
+
Access at: http://127.0.0.1:7861
|
| 82 |
+
|
| 83 |
+
## 🎨 UI Highlights
|
| 84 |
+
|
| 85 |
+
- **Purple-to-violet gradient** backgrounds
|
| 86 |
+
- **Pink-to-red** accent headers
|
| 87 |
+
- **Glassmorphism effects** for modern look
|
| 88 |
+
- **Smooth animations** on interactions
|
| 89 |
+
- **6 tabbed workflow** with progress indicators
|
| 90 |
+
|
| 91 |
+
## 🔧 Technical Architecture
|
| 92 |
+
|
| 93 |
+
### RAG Implementation
|
| 94 |
+
- **ChromaDB** for vector storage
|
| 95 |
+
- **SentenceTransformers** (all-MiniLM-L6-v2) for embeddings
|
| 96 |
+
- **5 pre-loaded templates**: Daily sales, CDC, data quality, multi-source, incremental ETL
|
| 97 |
+
- **Semantic similarity search** for pattern matching
|
| 98 |
+
|
| 99 |
+
### MCP Tools
|
| 100 |
+
Each tool is decorated with `@gr.mcp.tool()` and integrated into the Gradio UI:
|
| 101 |
+
- Screenshot analysis uses Claude Vision API
|
| 102 |
+
- Script generation with Claude 3 Opus
|
| 103 |
+
- Cost simulation with configurable worker types
|
| 104 |
+
- CDK code generation for deployment
|
| 105 |
+
- Voice synthesis with ElevenLabs v2.x API
|
| 106 |
+
- RAG template search with relevance scoring
|
| 107 |
+
|
| 108 |
+
## 📊 Use Cases
|
| 109 |
+
|
| 110 |
+
Perfect for:
|
| 111 |
+
- **Data Engineers** building ETL pipelines
|
| 112 |
+
- **DevOps Teams** automating infrastructure
|
| 113 |
+
- **Analytics Teams** processing data workflows
|
| 114 |
+
- **Cloud Architects** designing data platforms
|
| 115 |
+
|
| 116 |
+
## 🎯 What Makes It Unique
|
| 117 |
+
|
| 118 |
+
Unlike generic ChatGPT prompts, PipelineForge MCP provides:
|
| 119 |
+
|
| 120 |
+
1. **Visual Analysis** - Upload AWS console screenshots
|
| 121 |
+
2. **Cost Awareness** - See expenses before deployment
|
| 122 |
+
3. **Template Learning** - RAG-powered pattern matching
|
| 123 |
+
4. **Voice Explanations** - Audio summaries of pipelines
|
| 124 |
+
5. **Production Export** - Ready-to-deploy CDK code
|
| 125 |
+
6. **Automatic Flow** - No manual copy/paste between steps
|
| 126 |
+
|
| 127 |
+
## 📦 Dependencies
|
| 128 |
+
|
| 129 |
+
- `gradio>=5.0.0` - MCP server framework
|
| 130 |
+
- `anthropic>=0.40.0` - Claude AI
|
| 131 |
+
- `elevenlabs>=0.2.0` - Text-to-speech
|
| 132 |
+
- `chromadb>=0.4.18` - Vector database
|
| 133 |
+
- `sentence-transformers>=2.2.0` - Embeddings
|
| 134 |
+
- `modal>=1.2.0` - Serverless compute
|
| 135 |
+
- `boto3>=1.34.0` - AWS SDK
|
| 136 |
+
|
| 137 |
+
## 🏗️ Project Structure
|
| 138 |
+
|
| 139 |
+
```
|
| 140 |
+
pipelineforge-mcp/
|
| 141 |
+
├── app.py # Main Gradio MCP server
|
| 142 |
+
├── rag_templates_minimal.py # RAG implementation
|
| 143 |
+
├── requirements.txt # Dependencies
|
| 144 |
+
├── README.md # This file
|
| 145 |
+
├── .env # API keys (not committed)
|
| 146 |
+
└── chroma_db/ # RAG vector storage
|
| 147 |
+
```
|
| 148 |
+
|
| 149 |
+
## 🎬 Demo
|
| 150 |
+
|
| 151 |
+
*[Demo video coming soon]*
|
| 152 |
+
|
| 153 |
+
## 🤝 Contributing
|
| 154 |
+
|
| 155 |
+
Built for the MCP 1st Birthday Hackathon!
|
| 156 |
+
|
| 157 |
+
## 📄 License
|
| 158 |
+
|
| 159 |
+
MIT License
|
| 160 |
+
|
| 161 |
+
## 🙏 Acknowledgments
|
| 162 |
+
|
| 163 |
+
- **Anthropic** - Claude AI for vision and text
|
| 164 |
+
- **ChromaDB** - Vector database for RAG
|
| 165 |
+
- **ElevenLabs** - Voice synthesis
|
| 166 |
+
- **Modal** - Serverless compute
|
| 167 |
+
- **Gradio** - MCP framework
|
| 168 |
+
|
| 169 |
+
---
|
| 170 |
+
|
| 171 |
+
**🏆 MCP 1st Birthday Hackathon | Track: MCP in Action (Enterprise)**
|
| 172 |
+
|
| 173 |
+
Built with ❤️ for data engineers
|
app.py
ADDED
|
@@ -0,0 +1,552 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
PipelineForge MCP - Gradio MCP Server for AWS Glue ETL Optimization
|
| 3 |
+
MCP 1st Birthday Hackathon Submission - AUTOMATIC DATA FLOW VERSION
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import os
|
| 7 |
+
import gradio as gr
|
| 8 |
+
from dotenv import load_dotenv
|
| 9 |
+
import anthropic
|
| 10 |
+
from elevenlabs.client import ElevenLabs
|
| 11 |
+
import json
|
| 12 |
+
from typing import List, Dict, Optional, Tuple
|
| 13 |
+
from PIL import Image
|
| 14 |
+
import io
|
| 15 |
+
import base64
|
| 16 |
+
|
| 17 |
+
load_dotenv()
|
| 18 |
+
|
| 19 |
+
# Initialize API clients
|
| 20 |
+
anthropic_client = anthropic.Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY"))
|
| 21 |
+
elevenlabs_api_key = os.getenv("ELEVENLABS_API_KEY")
|
| 22 |
+
elevenlabs_client = ElevenLabs(api_key=elevenlabs_api_key) if elevenlabs_api_key else None
|
| 23 |
+
|
| 24 |
+
# Initialize RAG (using minimal implementation - no LangChain conflicts)
|
| 25 |
+
template_store = None
|
| 26 |
+
try:
|
| 27 |
+
from rag_templates_minimal import get_template_store
|
| 28 |
+
template_store = get_template_store()
|
| 29 |
+
if template_store:
|
| 30 |
+
print("✅ RAG template store initialized")
|
| 31 |
+
else:
|
| 32 |
+
print("⚠️ RAG template store returned None")
|
| 33 |
+
except Exception as e:
|
| 34 |
+
print(f"⚠️ RAG disabled: {e}")
|
| 35 |
+
|
| 36 |
+
# ===========================
|
| 37 |
+
# CORE MCP TOOLS
|
| 38 |
+
# ===========================
|
| 39 |
+
|
| 40 |
+
@gr.mcp.tool()
|
| 41 |
+
def analyze_screenshot(image: Image.Image, requirements: str) -> Dict:
|
| 42 |
+
"""Analyze AWS console screenshot and extract ETL pipeline requirements."""
|
| 43 |
+
try:
|
| 44 |
+
buffered = io.BytesIO()
|
| 45 |
+
image.save(buffered, format="PNG")
|
| 46 |
+
img_str = base64.b64encode(buffered.getvalue()).decode()
|
| 47 |
+
|
| 48 |
+
message = anthropic_client.messages.create(
|
| 49 |
+
model="claude-3-opus-20240229",
|
| 50 |
+
max_tokens=2048,
|
| 51 |
+
messages=[{
|
| 52 |
+
"role": "user",
|
| 53 |
+
"content": [
|
| 54 |
+
{"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": img_str}},
|
| 55 |
+
{"type": "text", "text": f"""Analyze this AWS console screenshot and extract ETL pipeline requirements.
|
| 56 |
+
|
| 57 |
+
Additional context: {requirements}
|
| 58 |
+
|
| 59 |
+
Return JSON with: sources, transformations, targets, estimated_volume, frequency"""}
|
| 60 |
+
]
|
| 61 |
+
}]
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
response_text = message.content[0].text
|
| 65 |
+
try:
|
| 66 |
+
return json.loads(response_text)
|
| 67 |
+
except:
|
| 68 |
+
return {"analysis": response_text, "sources": [], "transformations": [], "targets": [], "estimated_volume": "50GB", "frequency": "daily"}
|
| 69 |
+
except Exception as e:
|
| 70 |
+
return {"error": f"Screenshot analysis failed: {str(e)}"}
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
@gr.mcp.tool()
|
| 74 |
+
def generate_glue_script(requirements: Dict, optimization_level: str = "balanced") -> Dict:
|
| 75 |
+
"""Generate optimized AWS Glue PySpark ETL script."""
|
| 76 |
+
try:
|
| 77 |
+
message = anthropic_client.messages.create(
|
| 78 |
+
model="claude-3-opus-20240229",
|
| 79 |
+
max_tokens=4096,
|
| 80 |
+
messages=[{"role": "user", "content": f"""Generate an optimized AWS Glue PySpark ETL script:
|
| 81 |
+
|
| 82 |
+
{json.dumps(requirements, indent=2)}
|
| 83 |
+
|
| 84 |
+
Optimization: {optimization_level}
|
| 85 |
+
|
| 86 |
+
Include error handling, logging, and AWS Glue best practices."""}]
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
return {"script": message.content[0].text, "optimization_level": optimization_level}
|
| 90 |
+
except Exception as e:
|
| 91 |
+
return {"error": f"Script generation failed: {str(e)}"}
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
@gr.mcp.tool()
|
| 95 |
+
def simulate_glue_cost(requirements: Dict, worker_type: str = "G.1X", num_workers: int = 2) -> Dict:
|
| 96 |
+
"""Simulate AWS Glue job cost."""
|
| 97 |
+
try:
|
| 98 |
+
pricing = {"G.1X": 0.44, "G.2X": 0.88, "G.4X": 1.76, "G.8X": 3.52}
|
| 99 |
+
volume_str = str(requirements.get("estimated_volume", "50GB"))
|
| 100 |
+
|
| 101 |
+
if "GB" in volume_str:
|
| 102 |
+
volume_gb = float(volume_str.replace("GB", "").strip())
|
| 103 |
+
base_time_minutes = volume_gb * 5
|
| 104 |
+
elif "TB" in volume_str:
|
| 105 |
+
volume_tb = float(volume_str.replace("TB", "").strip())
|
| 106 |
+
base_time_minutes = volume_tb * 1000 * 5
|
| 107 |
+
else:
|
| 108 |
+
base_time_minutes = 30
|
| 109 |
+
|
| 110 |
+
worker_multiplier = {"G.1X": 1.0, "G.2X": 0.6, "G.4X": 0.4, "G.8X": 0.25}
|
| 111 |
+
estimated_time_hours = (base_time_minutes * worker_multiplier.get(worker_type, 1.0)) / 60
|
| 112 |
+
|
| 113 |
+
dpu_per_worker = {"G.1X": 1, "G.2X": 2, "G.4X": 4, "G.8X": 8}
|
| 114 |
+
total_dpus = num_workers * dpu_per_worker.get(worker_type, 1)
|
| 115 |
+
hourly_cost = total_dpus * pricing.get(worker_type, 0.44)
|
| 116 |
+
total_cost = hourly_cost * estimated_time_hours
|
| 117 |
+
|
| 118 |
+
recommendations = []
|
| 119 |
+
if total_cost > 10:
|
| 120 |
+
recommendations.append("Consider G.1X workers for cost optimization")
|
| 121 |
+
if estimated_time_hours > 2:
|
| 122 |
+
recommendations.append("Consider partitioning data")
|
| 123 |
+
|
| 124 |
+
return {
|
| 125 |
+
"worker_type": worker_type,
|
| 126 |
+
"num_workers": num_workers,
|
| 127 |
+
"estimated_time_hours": round(estimated_time_hours, 2),
|
| 128 |
+
"hourly_cost_usd": round(hourly_cost, 2),
|
| 129 |
+
"total_cost_usd": round(total_cost, 2),
|
| 130 |
+
"total_dpus": total_dpus,
|
| 131 |
+
"recommendations": recommendations
|
| 132 |
+
}
|
| 133 |
+
except Exception as e:
|
| 134 |
+
return {"error": f"Cost simulation failed: {str(e)}"}
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
@gr.mcp.tool()
|
| 138 |
+
def generate_cdk_infrastructure(requirements: Dict, script: str) -> Dict:
|
| 139 |
+
"""Generate AWS CDK Python code."""
|
| 140 |
+
try:
|
| 141 |
+
message = anthropic_client.messages.create(
|
| 142 |
+
model="claude-3-opus-20240229",
|
| 143 |
+
max_tokens=4096,
|
| 144 |
+
messages=[{"role": "user", "content": f"""Generate AWS CDK Python code:
|
| 145 |
+
|
| 146 |
+
Requirements: {json.dumps(requirements, indent=2)}
|
| 147 |
+
Script: {script[:500]}...
|
| 148 |
+
|
| 149 |
+
Include Glue job, IAM, S3, CloudWatch, EventBridge."""}]
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
return {"cdk_code": message.content[0].text}
|
| 153 |
+
except Exception as e:
|
| 154 |
+
return {"error": f"CDK generation failed: {str(e)}"}
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
@gr.mcp.tool()
|
| 158 |
+
def generate_voice_explanation(content: str) -> str:
|
| 159 |
+
"""Generate voice narration using ElevenLabs TTS."""
|
| 160 |
+
try:
|
| 161 |
+
if not elevenlabs_client:
|
| 162 |
+
return "ElevenLabs API key not configured"
|
| 163 |
+
|
| 164 |
+
audio_generator = elevenlabs_client.text_to_speech.convert(
|
| 165 |
+
text=content[:1000],
|
| 166 |
+
voice_id="21m00Tcm4TlvDq8ikWAM",
|
| 167 |
+
model_id="eleven_monolingual_v1"
|
| 168 |
+
)
|
| 169 |
+
|
| 170 |
+
output_path = "narration.mp3"
|
| 171 |
+
with open(output_path, "wb") as f:
|
| 172 |
+
for chunk in audio_generator:
|
| 173 |
+
f.write(chunk)
|
| 174 |
+
|
| 175 |
+
return output_path
|
| 176 |
+
except Exception as e:
|
| 177 |
+
return f"Voice generation failed: {str(e)}"
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
@gr.mcp.tool()
|
| 181 |
+
def find_similar_pipelines(query: str, top_k: int = 3) -> Dict:
|
| 182 |
+
"""Find similar ETL pipeline templates using RAG."""
|
| 183 |
+
try:
|
| 184 |
+
if template_store is None:
|
| 185 |
+
return {"error": "Template store not initialized"}
|
| 186 |
+
|
| 187 |
+
similar = template_store.find_similar(query, top_k)
|
| 188 |
+
return {"query": query, "similar_templates": similar, "count": len(similar)}
|
| 189 |
+
except Exception as e:
|
| 190 |
+
return {"error": f"Template search failed: {str(e)}"}
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
# ===========================
|
| 194 |
+
# GRADIO UI - AUTOMATIC DATA FLOW
|
| 195 |
+
# ===========================
|
| 196 |
+
|
| 197 |
+
def create_ui():
|
| 198 |
+
"""Create Gradio interface with automatic data flow and colorful theme"""
|
| 199 |
+
|
| 200 |
+
# Custom CSS for colorful, modern theme
|
| 201 |
+
custom_css = """
|
| 202 |
+
/* Main container gradient background */
|
| 203 |
+
.gradio-container {
|
| 204 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
/* Header styling */
|
| 208 |
+
.main-header {
|
| 209 |
+
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
|
| 210 |
+
padding: 2rem;
|
| 211 |
+
border-radius: 15px;
|
| 212 |
+
margin-bottom: 2rem;
|
| 213 |
+
box-shadow: 0 8px 32px rgba(31, 38, 135, 0.37);
|
| 214 |
+
backdrop-filter: blur(4px);
|
| 215 |
+
border: 1px solid rgba(255, 255, 255, 0.18);
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
/* Tab styling */
|
| 219 |
+
.tab-nav button {
|
| 220 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 221 |
+
color: white !important;
|
| 222 |
+
border: none;
|
| 223 |
+
border-radius: 10px 10px 0 0;
|
| 224 |
+
padding: 12px 24px;
|
| 225 |
+
margin: 0 4px;
|
| 226 |
+
transition: all 0.3s ease;
|
| 227 |
+
font-weight: 600;
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
.tab-nav button:hover {
|
| 231 |
+
transform: translateY(-3px);
|
| 232 |
+
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
.tab-nav button.selected {
|
| 236 |
+
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
|
| 237 |
+
box-shadow: 0 5px 20px rgba(245, 87, 108, 0.5);
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
/* Button styling */
|
| 241 |
+
.primary-button {
|
| 242 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
|
| 243 |
+
border: none !important;
|
| 244 |
+
color: white !important;
|
| 245 |
+
padding: 14px 32px !important;
|
| 246 |
+
border-radius: 12px !important;
|
| 247 |
+
font-size: 16px !important;
|
| 248 |
+
font-weight: 600 !important;
|
| 249 |
+
transition: all 0.3s ease !important;
|
| 250 |
+
box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4) !important;
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
.primary-button:hover {
|
| 254 |
+
transform: translateY(-2px) !important;
|
| 255 |
+
box-shadow: 0 8px 30px rgba(102, 126, 234, 0.6) !important;
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
/* Card containers */
|
| 259 |
+
.gr-box, .gr-form, .gr-panel {
|
| 260 |
+
background: rgba(255, 255, 255, 0.95) !important;
|
| 261 |
+
border-radius: 15px !important;
|
| 262 |
+
padding: 1.5rem !important;
|
| 263 |
+
box-shadow: 0 8px 32px rgba(31, 38, 135, 0.15) !important;
|
| 264 |
+
backdrop-filter: blur(4px) !important;
|
| 265 |
+
border: 1px solid rgba(255, 255, 255, 0.3) !important;
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
/* Input fields */
|
| 269 |
+
input, textarea, select {
|
| 270 |
+
border: 2px solid #e0e7ff !important;
|
| 271 |
+
border-radius: 10px !important;
|
| 272 |
+
padding: 10px !important;
|
| 273 |
+
transition: all 0.3s ease !important;
|
| 274 |
+
background: white !important;
|
| 275 |
+
}
|
| 276 |
+
|
| 277 |
+
input:focus, textarea:focus, select:focus {
|
| 278 |
+
border-color: #667eea !important;
|
| 279 |
+
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1) !important;
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
/* Code blocks */
|
| 283 |
+
.code-container {
|
| 284 |
+
background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%) !important;
|
| 285 |
+
border-radius: 12px !important;
|
| 286 |
+
padding: 1rem !important;
|
| 287 |
+
box-shadow: 0 8px 32px rgba(30, 60, 114, 0.3) !important;
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
/* JSON output */
|
| 291 |
+
.json-container {
|
| 292 |
+
background: linear-gradient(135deg, #134e5e 0%, #71b280 100%) !important;
|
| 293 |
+
border-radius: 12px !important;
|
| 294 |
+
padding: 1rem !important;
|
| 295 |
+
color: white !important;
|
| 296 |
+
}
|
| 297 |
+
|
| 298 |
+
/* Success indicators */
|
| 299 |
+
.success-mark {
|
| 300 |
+
color: #10b981;
|
| 301 |
+
font-size: 1.2em;
|
| 302 |
+
font-weight: bold;
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
/* Step numbers */
|
| 306 |
+
.step-number {
|
| 307 |
+
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
|
| 308 |
+
color: white;
|
| 309 |
+
border-radius: 50%;
|
| 310 |
+
width: 40px;
|
| 311 |
+
height: 40px;
|
| 312 |
+
display: inline-flex;
|
| 313 |
+
align-items: center;
|
| 314 |
+
justify-content: center;
|
| 315 |
+
font-weight: bold;
|
| 316 |
+
margin-right: 10px;
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
/* Footer */
|
| 320 |
+
.footer {
|
| 321 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 322 |
+
padding: 1.5rem;
|
| 323 |
+
border-radius: 15px;
|
| 324 |
+
margin-top: 2rem;
|
| 325 |
+
color: white;
|
| 326 |
+
text-align: center;
|
| 327 |
+
box-shadow: 0 8px 32px rgba(102, 126, 234, 0.3);
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
/* Animations */
|
| 331 |
+
@keyframes pulse {
|
| 332 |
+
0%, 100% { opacity: 1; }
|
| 333 |
+
50% { opacity: 0.8; }
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
.animated-icon {
|
| 337 |
+
animation: pulse 2s ease-in-out infinite;
|
| 338 |
+
}
|
| 339 |
+
"""
|
| 340 |
+
|
| 341 |
+
with gr.Blocks(title="PipelineForge MCP") as demo:
|
| 342 |
+
# Inject custom CSS
|
| 343 |
+
gr.HTML(f"""
|
| 344 |
+
<style>
|
| 345 |
+
{custom_css}
|
| 346 |
+
</style>
|
| 347 |
+
""")
|
| 348 |
+
|
| 349 |
+
gr.HTML("""
|
| 350 |
+
<div class="main-header">
|
| 351 |
+
<h1 style="color: white; margin: 0; font-size: 3em; text-shadow: 2px 2px 4px rgba(0,0,0,0.2);">
|
| 352 |
+
🔧 PipelineForge MCP
|
| 353 |
+
</h1>
|
| 354 |
+
<p style="color: rgba(255,255,255,0.95); font-size: 1.3em; margin-top: 0.5rem;">
|
| 355 |
+
⚡ AWS Glue ETL Optimizer - Automatic Workflow ⚡
|
| 356 |
+
</p>
|
| 357 |
+
<p style="color: rgba(255,255,255,0.9); font-size: 1.1em; margin-top: 1rem;">
|
| 358 |
+
🎯 Each step automatically uses data from previous steps - no copy/paste needed!
|
| 359 |
+
</p>
|
| 360 |
+
</div>
|
| 361 |
+
""")
|
| 362 |
+
|
| 363 |
+
# Shared state
|
| 364 |
+
pipeline_state = gr.State({"requirements": {}, "script": "", "cost": {}, "cdk": ""})
|
| 365 |
+
|
| 366 |
+
with gr.Tabs() as tabs:
|
| 367 |
+
# Tab 1: Screenshot Analysis
|
| 368 |
+
with gr.Tab("1️⃣ Start: Analyze Screenshot") as tab1:
|
| 369 |
+
gr.Markdown("### Extract requirements from AWS console image")
|
| 370 |
+
|
| 371 |
+
with gr.Row():
|
| 372 |
+
with gr.Column():
|
| 373 |
+
img_input = gr.Image(type="pil", label="Upload Screenshot")
|
| 374 |
+
req_input = gr.Textbox(label="Description", placeholder="Daily sales ETL", lines=2)
|
| 375 |
+
analyze_btn = gr.Button("🔍 Analyze", variant="primary", size="lg")
|
| 376 |
+
with gr.Column():
|
| 377 |
+
analysis_out = gr.JSON(label="✅ Requirements Extracted")
|
| 378 |
+
gr.Markdown("**Next:** Go to Script Generation tab →")
|
| 379 |
+
|
| 380 |
+
def analyze_and_store(img, req, state):
|
| 381 |
+
result = analyze_screenshot(img, req) if img else {"estimated_volume": "50GB", "sources": [], "transformations": [], "targets": []}
|
| 382 |
+
state["requirements"] = result
|
| 383 |
+
return result, state
|
| 384 |
+
|
| 385 |
+
analyze_btn.click(analyze_and_store, [img_input, req_input, pipeline_state], [analysis_out, pipeline_state])
|
| 386 |
+
|
| 387 |
+
# Tab 2: Script Generation
|
| 388 |
+
with gr.Tab("2️⃣ Generate Script") as tab2:
|
| 389 |
+
gr.Markdown("### AI generates PySpark code automatically using requirements from Tab 1")
|
| 390 |
+
|
| 391 |
+
with gr.Row():
|
| 392 |
+
with gr.Column():
|
| 393 |
+
gr.Markdown("**Using requirements from Screenshot Analysis** ✅")
|
| 394 |
+
opt_level = gr.Radio(["cost", "performance", "balanced"], value="balanced", label="Optimization")
|
| 395 |
+
gen_script_btn = gr.Button("🚀 Generate Script", variant="primary", size="lg")
|
| 396 |
+
with gr.Column():
|
| 397 |
+
script_out = gr.Code(label="✅ Generated PySpark Script", language="python", lines=20)
|
| 398 |
+
gr.Markdown("**Next:** Go to Cost Simulation tab →")
|
| 399 |
+
|
| 400 |
+
def generate_and_store(opt, state):
|
| 401 |
+
reqs = state.get("requirements", {"estimated_volume": "50GB"})
|
| 402 |
+
result = generate_glue_script(reqs, opt)
|
| 403 |
+
script = result.get("script", "")
|
| 404 |
+
state["script"] = script
|
| 405 |
+
return script, state
|
| 406 |
+
|
| 407 |
+
gen_script_btn.click(generate_and_store, [opt_level, pipeline_state], [script_out, pipeline_state])
|
| 408 |
+
|
| 409 |
+
# Tab 3: Cost Simulation
|
| 410 |
+
with gr.Tab("3️⃣ Simulate Cost") as tab3:
|
| 411 |
+
gr.Markdown("### Calculate AWS Glue costs automatically using requirements from Tab 1")
|
| 412 |
+
|
| 413 |
+
with gr.Row():
|
| 414 |
+
with gr.Column():
|
| 415 |
+
gr.Markdown("**Using requirements from Screenshot Analysis** ✅")
|
| 416 |
+
worker_type = gr.Dropdown(["G.1X", "G.2X", "G.4X", "G.8X"], value="G.1X", label="Worker Type")
|
| 417 |
+
num_workers = gr.Slider(2, 50, 5, step=1, label="Workers")
|
| 418 |
+
cost_btn = gr.Button("💵 Simulate Cost", variant="primary", size="lg")
|
| 419 |
+
with gr.Column():
|
| 420 |
+
cost_out = gr.JSON(label="✅ Cost Breakdown")
|
| 421 |
+
gr.Markdown("**Next:** Go to CDK Infrastructure tab →")
|
| 422 |
+
|
| 423 |
+
def simulate_and_store(worker, workers, state):
|
| 424 |
+
reqs = state.get("requirements", {"estimated_volume": "50GB"})
|
| 425 |
+
result = simulate_glue_cost(reqs, worker, workers)
|
| 426 |
+
state["cost"] = result
|
| 427 |
+
return result, state
|
| 428 |
+
|
| 429 |
+
cost_btn.click(simulate_and_store, [worker_type, num_workers, pipeline_state], [cost_out, pipeline_state])
|
| 430 |
+
|
| 431 |
+
# Tab 4: CDK Infrastructure
|
| 432 |
+
with gr.Tab("4️⃣ Generate CDK") as tab4:
|
| 433 |
+
gr.Markdown("### Generate deployment code automatically using requirements + script from previous tabs")
|
| 434 |
+
|
| 435 |
+
with gr.Row():
|
| 436 |
+
with gr.Column():
|
| 437 |
+
gr.Markdown("**Using requirements from Tab 1 + script from Tab 2** ✅")
|
| 438 |
+
cdk_btn = gr.Button("🏭 Generate CDK", variant="primary", size="lg")
|
| 439 |
+
with gr.Column():
|
| 440 |
+
cdk_out = gr.Code(label="✅ AWS CDK Python Code", language="python", lines=20)
|
| 441 |
+
gr.Markdown("**Next:** Go to Voice Summary tab →")
|
| 442 |
+
|
| 443 |
+
def generate_cdk_and_store(state):
|
| 444 |
+
reqs = state.get("requirements", {})
|
| 445 |
+
script = state.get("script", "")
|
| 446 |
+
result = generate_cdk_infrastructure(reqs, script)
|
| 447 |
+
cdk = result.get("cdk_code", "")
|
| 448 |
+
state["cdk"] = cdk
|
| 449 |
+
return cdk, state
|
| 450 |
+
|
| 451 |
+
cdk_btn.click(generate_cdk_and_store, [pipeline_state], [cdk_out, pipeline_state])
|
| 452 |
+
|
| 453 |
+
# Tab 5: Voice Summary
|
| 454 |
+
with gr.Tab("5️⃣ Voice Summary") as tab5:
|
| 455 |
+
gr.Markdown("### Automatic voice narration of your complete pipeline")
|
| 456 |
+
|
| 457 |
+
with gr.Row():
|
| 458 |
+
with gr.Column():
|
| 459 |
+
gr.Markdown("**Automatically summarizes ALL previous tabs** ✅")
|
| 460 |
+
voice_btn = gr.Button("🎤 Generate Voice Summary", variant="primary", size="lg")
|
| 461 |
+
summary_text = gr.Textbox(label="Summary (auto-generated)", lines=10)
|
| 462 |
+
with gr.Column():
|
| 463 |
+
audio_out = gr.Audio(label="✅ Voice Narration")
|
| 464 |
+
status_out = gr.Textbox(label="Status")
|
| 465 |
+
|
| 466 |
+
def generate_voice_summary(state):
|
| 467 |
+
parts = []
|
| 468 |
+
|
| 469 |
+
reqs = state.get("requirements", {})
|
| 470 |
+
if reqs:
|
| 471 |
+
volume = reqs.get("estimated_volume", "unknown")
|
| 472 |
+
sources = ", ".join(reqs.get("sources", []))[:50]
|
| 473 |
+
parts.append(f"This ETL pipeline processes {volume} of data")
|
| 474 |
+
if sources:
|
| 475 |
+
parts.append(f"from {sources}")
|
| 476 |
+
|
| 477 |
+
cost = state.get("cost", {})
|
| 478 |
+
if cost and "total_cost_usd" in cost:
|
| 479 |
+
cost_val = cost["total_cost_usd"]
|
| 480 |
+
time_val = cost["estimated_time_hours"]
|
| 481 |
+
workers = cost["num_workers"]
|
| 482 |
+
parts.append(f"using {workers} workers. It costs ${cost_val:.2f} per run, taking {time_val:.1f} hours.")
|
| 483 |
+
|
| 484 |
+
if state.get("script"):
|
| 485 |
+
parts.append("Complete PySpark script has been generated with AWS Glue best practices.")
|
| 486 |
+
|
| 487 |
+
if state.get("cdk"):
|
| 488 |
+
parts.append("Infrastructure code is ready for deployment with CDK.")
|
| 489 |
+
|
| 490 |
+
summary = " ".join(parts) if parts else "Complete the previous tabs first to generate summary."
|
| 491 |
+
|
| 492 |
+
audio_path = generate_voice_explanation(summary)
|
| 493 |
+
status = "✅ Voice generated!" if not audio_path.startswith("Voice generation failed") else "❌ " + audio_path
|
| 494 |
+
|
| 495 |
+
return summary, audio_path, status
|
| 496 |
+
|
| 497 |
+
voice_btn.click(generate_voice_summary, [pipeline_state], [summary_text, audio_out, status_out])
|
| 498 |
+
|
| 499 |
+
# Tab 6: Template Library
|
| 500 |
+
with gr.Tab("6️⃣ Find Similar Templates") as tab6:
|
| 501 |
+
gr.Markdown("### Search ETL template library with RAG")
|
| 502 |
+
|
| 503 |
+
with gr.Row():
|
| 504 |
+
with gr.Column():
|
| 505 |
+
# Dropdown with pre-defined queries
|
| 506 |
+
template_dropdown = gr.Dropdown(
|
| 507 |
+
choices=[
|
| 508 |
+
"Daily sales aggregation with customer join",
|
| 509 |
+
"Real-time CDC processing from DynamoDB",
|
| 510 |
+
"Data quality validation with Great Expectations",
|
| 511 |
+
"Multi-source data lake integration",
|
| 512 |
+
"Incremental ETL with job bookmarks",
|
| 513 |
+
"Custom query..."
|
| 514 |
+
],
|
| 515 |
+
label="Select Template Type",
|
| 516 |
+
value="Daily sales aggregation with customer join"
|
| 517 |
+
)
|
| 518 |
+
custom_query = gr.Textbox(label="Or enter custom query", placeholder="Describe your ETL needs", lines=2)
|
| 519 |
+
search_btn = gr.Button("🔍 Find Templates", variant="primary")
|
| 520 |
+
with gr.Column():
|
| 521 |
+
template_out = gr.JSON(label="✅ Similar Templates")
|
| 522 |
+
|
| 523 |
+
def search_templates(dropdown_val, custom_val):
|
| 524 |
+
query = custom_val if custom_val else dropdown_val
|
| 525 |
+
return find_similar_pipelines(query, 3)
|
| 526 |
+
|
| 527 |
+
search_btn.click(search_templates, [template_dropdown, custom_query], template_out)
|
| 528 |
+
|
| 529 |
+
gr.HTML("""
|
| 530 |
+
<div class="footer">
|
| 531 |
+
<h2 style="margin: 0; color: white; text-shadow: 2px 2px 4px rgba(0,0,0,0.2);">
|
| 532 |
+
🏆 MCP 1st Birthday Hackathon
|
| 533 |
+
</h2>
|
| 534 |
+
<p style="margin-top: 0.5rem; font-size: 1.2em; color: rgba(255,255,255,0.95);">
|
| 535 |
+
✨ All 6 features with automatic data flow ✨
|
| 536 |
+
</p>
|
| 537 |
+
<p style="margin-top: 0.5rem; color: rgba(255,255,255,0.9);">
|
| 538 |
+
🎯 ChromaDB RAG | ⚡ Modal Testing | 🧠 Claude AI | 🎙️ ElevenLabs TTS
|
| 539 |
+
</p>
|
| 540 |
+
</div>
|
| 541 |
+
""")
|
| 542 |
+
|
| 543 |
+
return demo
|
| 544 |
+
|
| 545 |
+
|
| 546 |
+
if __name__ == "__main__":
|
| 547 |
+
demo = create_ui()
|
| 548 |
+
demo.launch(
|
| 549 |
+
server_name=os.getenv("GRADIO_SERVER_NAME", "127.0.0.1"),
|
| 550 |
+
server_port=int(os.getenv("GRADIO_SERVER_PORT", "7860")),
|
| 551 |
+
share=False
|
| 552 |
+
)
|
rag_templates_minimal.py
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Minimal RAG Template Store - No LlamaIndex, No LangChain
|
| 3 |
+
Uses only: ChromaDB + SentenceTransformers
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import os
|
| 7 |
+
import chromadb
|
| 8 |
+
from sentence_transformers import SentenceTransformer
|
| 9 |
+
from typing import List, Dict, Optional
|
| 10 |
+
import json
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class ETLTemplateStore:
|
| 14 |
+
"""Minimal RAG store using ChromaDB + SentenceTransformers directly"""
|
| 15 |
+
|
| 16 |
+
def __init__(self, persist_dir: str = "./chroma_db"):
|
| 17 |
+
"""Initialize with direct ChromaDB and embeddings"""
|
| 18 |
+
self.persist_dir = persist_dir
|
| 19 |
+
self.collection = None
|
| 20 |
+
self.model = None
|
| 21 |
+
|
| 22 |
+
try:
|
| 23 |
+
print("🔧 Initializing Minimal RAG Template Store...")
|
| 24 |
+
|
| 25 |
+
# Load embeddings model (local, no API needed)
|
| 26 |
+
self.model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
|
| 27 |
+
print("✓ Embeddings model loaded")
|
| 28 |
+
|
| 29 |
+
# Initialize ChromaDB
|
| 30 |
+
self.chroma_client = chromadb.PersistentClient(path=persist_dir)
|
| 31 |
+
self.collection = self.chroma_client.get_or_create_collection(
|
| 32 |
+
name="etl_templates",
|
| 33 |
+
metadata={"hnsw:space": "cosine"}
|
| 34 |
+
)
|
| 35 |
+
print("✓ ChromaDB initialized")
|
| 36 |
+
|
| 37 |
+
# Add default templates if collection is empty
|
| 38 |
+
if self.collection.count() == 0:
|
| 39 |
+
self._add_default_templates()
|
| 40 |
+
print("✓ Added default templates")
|
| 41 |
+
else:
|
| 42 |
+
print(f"✓ Loaded {self.collection.count()} existing templates")
|
| 43 |
+
|
| 44 |
+
print("✅ RAG Template Store ready!")
|
| 45 |
+
|
| 46 |
+
except Exception as e:
|
| 47 |
+
print(f"⚠️ RAG initialization failed: {e}")
|
| 48 |
+
raise
|
| 49 |
+
|
| 50 |
+
def _add_default_templates(self):
|
| 51 |
+
"""Add 5 default AWS Glue ETL templates"""
|
| 52 |
+
templates = [
|
| 53 |
+
{
|
| 54 |
+
"id": "template_1",
|
| 55 |
+
"name": "Daily Sales Aggregation",
|
| 56 |
+
"description": "Aggregate daily sales data with customer join and date filtering for e-commerce reporting",
|
| 57 |
+
"use_case": "E-commerce daily reporting with customer dimensions",
|
| 58 |
+
"estimated_cost": "$5-10 per day",
|
| 59 |
+
"worker_config": "G.1X with 5 workers",
|
| 60 |
+
"data_volume": "50-100GB"
|
| 61 |
+
},
|
| 62 |
+
{
|
| 63 |
+
"id": "template_2",
|
| 64 |
+
"name": "Real-time CDC Processing",
|
| 65 |
+
"description": "Process change data capture events from DynamoDB streams for real-time sync",
|
| 66 |
+
"use_case": "Real-time data sync between operational and analytical stores",
|
| 67 |
+
"estimated_cost": "$20-40 per day",
|
| 68 |
+
"worker_config": "G.2X with 3 workers",
|
| 69 |
+
"data_volume": "Streaming 10K events/min"
|
| 70 |
+
},
|
| 71 |
+
{
|
| 72 |
+
"id": "template_3",
|
| 73 |
+
"name": "Data Quality Validation",
|
| 74 |
+
"description": "Validate data quality with Great Expectations before loading to ensure data integrity",
|
| 75 |
+
"use_case": "Data quality checks in ETL pipelines",
|
| 76 |
+
"estimated_cost": "$3-8 per run",
|
| 77 |
+
"worker_config": "G.1X with 2 workers",
|
| 78 |
+
"data_volume": "10-50GB"
|
| 79 |
+
},
|
| 80 |
+
{
|
| 81 |
+
"id": "template_4",
|
| 82 |
+
"name": "Multi-Source Data Lake Integration",
|
| 83 |
+
"description": "Combine data from S3, RDS, and Redshift into unified data lake",
|
| 84 |
+
"use_case": "Centralized data lake from multiple sources",
|
| 85 |
+
"estimated_cost": "$15-30 per run",
|
| 86 |
+
"worker_config": "G.2X with 10 workers",
|
| 87 |
+
"data_volume": "500GB-2TB"
|
| 88 |
+
},
|
| 89 |
+
{
|
| 90 |
+
"id": "template_5",
|
| 91 |
+
"name": "Incremental ETL with Job Bookmarks",
|
| 92 |
+
"description": "Process only new data using Glue job bookmarks for efficient incremental loading",
|
| 93 |
+
"use_case": "Efficient incremental data processing",
|
| 94 |
+
"estimated_cost": "$2-5 per run",
|
| 95 |
+
"worker_config": "G.1X with 2 workers",
|
| 96 |
+
"data_volume": "Incremental varies"
|
| 97 |
+
}
|
| 98 |
+
]
|
| 99 |
+
|
| 100 |
+
for template in templates:
|
| 101 |
+
self.add_template(template)
|
| 102 |
+
|
| 103 |
+
def add_template(self, template: Dict):
|
| 104 |
+
"""Add template to ChromaDB with embeddings"""
|
| 105 |
+
try:
|
| 106 |
+
# Create searchable text
|
| 107 |
+
search_text = f"{template['name']} {template['description']} {template['use_case']}"
|
| 108 |
+
|
| 109 |
+
# Generate embedding
|
| 110 |
+
embedding = self.model.encode(search_text).tolist()
|
| 111 |
+
|
| 112 |
+
# Add to ChromaDB
|
| 113 |
+
self.collection.add(
|
| 114 |
+
ids=[template['id']],
|
| 115 |
+
embeddings=[embedding],
|
| 116 |
+
documents=[search_text],
|
| 117 |
+
metadatas=[template]
|
| 118 |
+
)
|
| 119 |
+
print(f"✓ Added: {template['name']}")
|
| 120 |
+
|
| 121 |
+
except Exception as e:
|
| 122 |
+
print(f"⚠️ Error adding template: {e}")
|
| 123 |
+
|
| 124 |
+
def find_similar(self, query: str, top_k: int = 3) -> List[Dict]:
|
| 125 |
+
"""Find similar templates using semantic search"""
|
| 126 |
+
if not self.collection or not self.model:
|
| 127 |
+
return []
|
| 128 |
+
|
| 129 |
+
try:
|
| 130 |
+
# Generate query embedding
|
| 131 |
+
query_embedding = self.model.encode(query).tolist()
|
| 132 |
+
|
| 133 |
+
# Search ChromaDB
|
| 134 |
+
results = self.collection.query(
|
| 135 |
+
query_embeddings=[query_embedding],
|
| 136 |
+
n_results=min(top_k, self.collection.count())
|
| 137 |
+
)
|
| 138 |
+
|
| 139 |
+
# Format results
|
| 140 |
+
similar_templates = []
|
| 141 |
+
if results and results['metadatas'] and results['metadatas'][0]:
|
| 142 |
+
for i, metadata in enumerate(results['metadatas'][0]):
|
| 143 |
+
distance = results['distances'][0][i] if results.get('distances') else 0
|
| 144 |
+
# Convert distance to similarity score (1 - distance for cosine)
|
| 145 |
+
similarity = 1.0 - distance
|
| 146 |
+
|
| 147 |
+
similar_templates.append({
|
| 148 |
+
"template": metadata,
|
| 149 |
+
"relevance_score": round(similarity, 3),
|
| 150 |
+
"excerpt": results['documents'][0][i][:150] + "..."
|
| 151 |
+
})
|
| 152 |
+
|
| 153 |
+
return similar_templates
|
| 154 |
+
|
| 155 |
+
except Exception as e:
|
| 156 |
+
print(f"⚠️ Search error: {e}")
|
| 157 |
+
return []
|
| 158 |
+
|
| 159 |
+
def get_all_templates(self) -> List[Dict]:
|
| 160 |
+
"""Get all stored templates"""
|
| 161 |
+
if not self.collection:
|
| 162 |
+
return []
|
| 163 |
+
|
| 164 |
+
try:
|
| 165 |
+
all_data = self.collection.get()
|
| 166 |
+
return all_data.get('metadatas', [])
|
| 167 |
+
except Exception as e:
|
| 168 |
+
print(f"⚠️ Error retrieving templates: {e}")
|
| 169 |
+
return []
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
# Singleton
|
| 173 |
+
_template_store = None
|
| 174 |
+
|
| 175 |
+
def get_template_store() -> Optional[ETLTemplateStore]:
|
| 176 |
+
"""Get or create global template store"""
|
| 177 |
+
global _template_store
|
| 178 |
+
if _template_store is None:
|
| 179 |
+
try:
|
| 180 |
+
_template_store = ETLTemplateStore()
|
| 181 |
+
except Exception as e:
|
| 182 |
+
print(f"⚠️ Could not initialize template store: {e}")
|
| 183 |
+
return None
|
| 184 |
+
return _template_store
|
requirements.txt
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Core Framework
|
| 2 |
+
gradio>=5.0.0
|
| 3 |
+
python-dotenv==1.0.0
|
| 4 |
+
|
| 5 |
+
# AI & Voice
|
| 6 |
+
anthropic>=0.40.0
|
| 7 |
+
elevenlabs>=0.2.0
|
| 8 |
+
|
| 9 |
+
# Compute
|
| 10 |
+
modal>=1.2.0
|
| 11 |
+
|
| 12 |
+
# RAG & Embeddings (Minimal - No LangChain conflicts)
|
| 13 |
+
chromadb>=0.4.18
|
| 14 |
+
sentence-transformers>=2.2.0
|
| 15 |
+
pyarrow==14.0.1
|
| 16 |
+
|
| 17 |
+
# AWS & Cloud
|
| 18 |
+
boto3>=1.34.0
|
| 19 |
+
|
| 20 |
+
# Data Processing
|
| 21 |
+
pillow>=10.0.0
|
| 22 |
+
pyyaml>=6.0.0
|
| 23 |
+
pandas>=2.0.0
|
| 24 |
+
|
| 25 |
+
# Utils
|
| 26 |
+
requests>=2.31.0
|