Spaces:
Sleeping
Sleeping
dboa9 commited on
Commit ·
4fdd358
1
Parent(s): b68e63a
Add workspace config and offload script
Browse files- Dockerfile +23 -18
- MoltbotEngine.code-workspace +18 -0
- README.md +1 -0
- app.py +60 -35
- requirements.txt +1 -0
- sync_projects.sh +37 -0
- trigger_cloud.py.txt +52 -0
Dockerfile
CHANGED
|
@@ -1,28 +1,33 @@
|
|
|
|
|
| 1 |
FROM python:3.11-slim
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
# Install system dependencies
|
| 6 |
RUN apt-get update && apt-get install -y \
|
| 7 |
-
|
| 8 |
-
curl \
|
| 9 |
-
|
| 10 |
-
libpq-dev \
|
| 11 |
&& rm -rf /var/lib/apt/lists/*
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
|
| 15 |
-
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
|
| 20 |
-
#
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
# Expose
|
|
|
|
| 25 |
EXPOSE 7860
|
| 26 |
|
| 27 |
-
# Start
|
| 28 |
-
CMD ["
|
|
|
|
| 1 |
+
# CORRECTED Dockerfile for FastAPI + OpenClaw
|
| 2 |
FROM python:3.11-slim
|
| 3 |
|
| 4 |
+
# 1. Install Node.js for OpenClaw
|
|
|
|
|
|
|
| 5 |
RUN apt-get update && apt-get install -y \
|
| 6 |
+
curl gnupg \
|
| 7 |
+
&& curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \
|
| 8 |
+
&& apt-get install -y nodejs python3-pip \
|
|
|
|
| 9 |
&& rm -rf /var/lib/apt/lists/*
|
| 10 |
|
| 11 |
+
# 2. Create secure user
|
| 12 |
+
RUN useradd -m -u 1000 appuser && \
|
| 13 |
+
mkdir -p /app && chown -R appuser:appuser /app
|
| 14 |
|
| 15 |
+
USER appuser
|
| 16 |
+
WORKDIR /app
|
| 17 |
|
| 18 |
+
# 3. Install OpenClaw (locally, not globally)
|
| 19 |
+
COPY --chown=appuser package.json package-lock.json ./
|
| 20 |
+
RUN npm install
|
| 21 |
+
|
| 22 |
+
# 4. Copy Python code
|
| 23 |
+
COPY --chown=appuser . .
|
| 24 |
+
|
| 25 |
+
# 5. Install Python dependencies
|
| 26 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 27 |
|
| 28 |
+
# 6. Expose FastAPI port
|
| 29 |
+
ENV PORT=7860
|
| 30 |
EXPOSE 7860
|
| 31 |
|
| 32 |
+
# 7. Start FastAPI, which can call OpenClaw as needed
|
| 33 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
MoltbotEngine.code-workspace
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"folders": [
|
| 3 |
+
{
|
| 4 |
+
"name": "Moltbot Hybrid Engine",
|
| 5 |
+
"path": "/home/mrdbo/projects/moltbot-hybrid-engine"
|
| 6 |
+
}
|
| 7 |
+
],
|
| 8 |
+
"settings": {
|
| 9 |
+
"python.defaultInterpreterPath": "/home/mrdbo/projects/courtBundleGenerator2/court_venv_20250802/bin/python",
|
| 10 |
+
"[python]": {
|
| 11 |
+
"editor.formatOnSave": true
|
| 12 |
+
},
|
| 13 |
+
"python.analysis.extraPaths": [
|
| 14 |
+
"/home/mrdbo/projects/courtBundleGenerator2",
|
| 15 |
+
"/home/mrdbo/projects/courtBundleGenerator3"
|
| 16 |
+
]
|
| 17 |
+
}
|
| 18 |
+
}
|
README.md
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
---
|
| 2 |
title: Moltbot Hybrid Engine
|
| 3 |
emoji: ⚖️
|
|
|
|
| 1 |
+
#/home/mrdbo/projects/moltbot-hybrid-engine/README.md
|
| 2 |
---
|
| 3 |
title: Moltbot Hybrid Engine
|
| 4 |
emoji: ⚖️
|
app.py
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI, HTTPException
|
| 2 |
from pydantic import BaseModel
|
| 3 |
import subprocess
|
| 4 |
import os
|
|
|
|
| 5 |
from pathlib import Path
|
|
|
|
| 6 |
|
| 7 |
app = FastAPI(title="Moltbot Hybrid Engine")
|
| 8 |
|
|
@@ -11,46 +15,67 @@ class BundleRequest(BaseModel):
|
|
| 11 |
limit: int = 15
|
| 12 |
evidence_filter: str = None
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
return {
|
| 17 |
-
"status": "online",
|
| 18 |
-
"service": "Moltbot Hybrid Engine",
|
| 19 |
-
"version": "1.0.0",
|
| 20 |
-
"endpoints": {
|
| 21 |
-
"health": "/health",
|
| 22 |
-
"process": "/process",
|
| 23 |
-
"status": "/status/{job_id}"
|
| 24 |
-
}
|
| 25 |
-
}
|
| 26 |
-
|
| 27 |
-
@app.get("/health")
|
| 28 |
-
async def health():
|
| 29 |
-
return {"status": "healthy"}
|
| 30 |
|
| 31 |
@app.post("/process")
|
| 32 |
async def process_bundle(request: BundleRequest):
|
| 33 |
-
"""
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
try:
|
| 37 |
-
#
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
"status"
|
| 42 |
-
"
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
except Exception as e:
|
| 47 |
-
|
|
|
|
| 48 |
|
| 49 |
@app.get("/status/{job_id}")
|
| 50 |
async def get_status(job_id: str):
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
"result_url": f"https://example.com/results/{job_id}"
|
| 56 |
-
}
|
|
|
|
| 1 |
+
|
| 2 |
+
#/home/mrdbo/projects/moltbot-hybrid-engine/app.py# CORRECTED app.py for Hugging Face Space
|
| 3 |
from fastapi import FastAPI, HTTPException
|
| 4 |
from pydantic import BaseModel
|
| 5 |
import subprocess
|
| 6 |
import os
|
| 7 |
+
import json
|
| 8 |
from pathlib import Path
|
| 9 |
+
import asyncio
|
| 10 |
|
| 11 |
app = FastAPI(title="Moltbot Hybrid Engine")
|
| 12 |
|
|
|
|
| 15 |
limit: int = 15
|
| 16 |
evidence_filter: str = None
|
| 17 |
|
| 18 |
+
# Store job status (in production, use a database)
|
| 19 |
+
jobs = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@app.post("/process")
|
| 22 |
async def process_bundle(request: BundleRequest):
|
| 23 |
+
"""Process bundle IN THE CLOUD - no local references"""
|
| 24 |
+
job_id = f"job_{len(jobs) + 1}"
|
| 25 |
+
|
| 26 |
+
# Run processing ASYNCHRONOUSLY
|
| 27 |
+
asyncio.create_task(run_bundler_async(job_id, request))
|
| 28 |
+
|
| 29 |
+
jobs[job_id] = {
|
| 30 |
+
"status": "processing",
|
| 31 |
+
"project": request.project,
|
| 32 |
+
"limit": request.limit,
|
| 33 |
+
"started_at": "2024-01-15T10:30:00Z"
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
return {
|
| 37 |
+
"job_id": job_id,
|
| 38 |
+
"status": "queued",
|
| 39 |
+
"message": f"Processing {request.project} with limit={request.limit} IN THE CLOUD",
|
| 40 |
+
"estimated_time": "2-5 minutes"
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
async def run_bundler_async(job_id: str, request: BundleRequest):
|
| 44 |
+
"""Run the court bundler inside the container"""
|
| 45 |
try:
|
| 46 |
+
# Path is INSIDE the container
|
| 47 |
+
bundler_path = Path("/app/court_project/generate_bundles_final_corrected.py")
|
| 48 |
+
|
| 49 |
+
if not bundler_path.exists():
|
| 50 |
+
jobs[job_id]["status"] = "failed"
|
| 51 |
+
jobs[job_id]["error"] = f"Bundler not found at {bundler_path}"
|
| 52 |
+
return
|
| 53 |
+
|
| 54 |
+
# Run the bundler
|
| 55 |
+
cmd = [
|
| 56 |
+
"python", str(bundler_path),
|
| 57 |
+
"--limit", str(request.limit)
|
| 58 |
+
]
|
| 59 |
+
|
| 60 |
+
result = subprocess.run(
|
| 61 |
+
cmd,
|
| 62 |
+
capture_output=True,
|
| 63 |
+
text=True,
|
| 64 |
+
cwd="/app/court_project"
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
# Update job status
|
| 68 |
+
jobs[job_id]["status"] = "completed" if result.returncode == 0 else "failed"
|
| 69 |
+
jobs[job_id]["output"] = result.stdout
|
| 70 |
+
jobs[job_id]["error"] = result.stderr if result.returncode != 0 else None
|
| 71 |
+
|
| 72 |
except Exception as e:
|
| 73 |
+
jobs[job_id]["status"] = "failed"
|
| 74 |
+
jobs[job_id]["error"] = str(e)
|
| 75 |
|
| 76 |
@app.get("/status/{job_id}")
|
| 77 |
async def get_status(job_id: str):
|
| 78 |
+
if job_id not in jobs:
|
| 79 |
+
raise HTTPException(status_code=404, detail="Job not found")
|
| 80 |
+
|
| 81 |
+
return jobs[job_id]
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
fastapi>=0.104.0
|
| 2 |
uvicorn>=0.24.0
|
| 3 |
pydantic>=2.4.0
|
|
|
|
| 1 |
+
#/home/mrdbo/projects/moltbot-hybrid-engine/requirements.txt
|
| 2 |
fastapi>=0.104.0
|
| 3 |
uvicorn>=0.24.0
|
| 4 |
pydantic>=2.4.0
|
sync_projects.sh
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# Script to sync between local projects and Hugging Face
|
| 3 |
+
|
| 4 |
+
echo "🔗 Syncing project configurations..."
|
| 5 |
+
|
| 6 |
+
# 1. Copy updated workspace config
|
| 7 |
+
cp /home/mrdbo/projects/MyProjects.code-workspace /home/mrdbo/projects/moltbot-hybrid-engine/
|
| 8 |
+
|
| 9 |
+
# 2. Copy critical instructions for reference
|
| 10 |
+
cp /home/mrdbo/projects/courtBundleGenerator2/memory-bank/CRITICAL_INSTRUCTIONS.md /home/mrdbo/projects/moltbot-hybrid-engine/
|
| 11 |
+
|
| 12 |
+
# 3. Generate project manifest
|
| 13 |
+
cat > /home/mrdbo/projects/moltbot-hybrid-engine/PROJECT_MANIFEST.md << EOF
|
| 14 |
+
# Project Manifest - $(date)
|
| 15 |
+
|
| 16 |
+
## Active Projects
|
| 17 |
+
1. **courtBundleGenerator2** - Legacy bundler with enhanced features
|
| 18 |
+
- Path: /home/mrdbo/projects/courtBundleGenerator2
|
| 19 |
+
- Entry: enhanced_bundler_wrapper.patched.py
|
| 20 |
+
- Output: /home/mrdbo/court_data/CourtBundleOutput
|
| 21 |
+
|
| 22 |
+
2. **courtBundleGenerator3** - Main bundler with dual categorization
|
| 23 |
+
- Path: /home/mrdbo/projects/courtBundleGenerator3
|
| 24 |
+
- Entry: generate_bundles_final_corrected.py
|
| 25 |
+
- Output: /home/mrdbo/court_data/2nd_CourtBundleOutput
|
| 26 |
+
|
| 27 |
+
3. **moltbot-hybrid-engine** - Cloud processing & JIRA integration
|
| 28 |
+
- Path: /home/mrdbo/projects/moltbot-hybrid-engine
|
| 29 |
+
- Cloud: https://huggingface.co/spaces/deebee7/moltbot-hybrid-engine
|
| 30 |
+
- Purpose: GPU acceleration & automated workflows
|
| 31 |
+
|
| 32 |
+
## Synchronization
|
| 33 |
+
- Workspace: MyProjects.code-workspace
|
| 34 |
+
- Last sync: $(date)
|
| 35 |
+
EOF
|
| 36 |
+
|
| 37 |
+
echo "✅ Sync complete!"
|
trigger_cloud.py.txt
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# /home/mrdbo/projects/moltbot-hybrid-engine/trigger_cloud.py
|
| 2 |
+
import requests
|
| 3 |
+
import sys
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
# Get from Hugging Face Space → "Embed this Space"
|
| 7 |
+
HF_SPACE_URL = "https://yourusername-moltbot-hybrid-engine.hf.space"
|
| 8 |
+
|
| 9 |
+
def trigger_bundler(limit=15, project="p3"):
|
| 10 |
+
"""Send request to cloud API - ONE WAY ONLY"""
|
| 11 |
+
payload = {
|
| 12 |
+
"project": project,
|
| 13 |
+
"limit": limit,
|
| 14 |
+
"evidence_filter": None
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
try:
|
| 18 |
+
response = requests.post(
|
| 19 |
+
f"{HF_SPACE_URL}/process",
|
| 20 |
+
json=payload,
|
| 21 |
+
timeout=30
|
| 22 |
+
)
|
| 23 |
+
if response.status_code == 200:
|
| 24 |
+
data = response.json()
|
| 25 |
+
print(f"✅ Job started: {data.get('job_id')}")
|
| 26 |
+
print(f" Status: {data.get('status')}")
|
| 27 |
+
print(f" Message: {data.get('message')}")
|
| 28 |
+
return True
|
| 29 |
+
else:
|
| 30 |
+
print(f"❌ Failed: {response.status_code} - {response.text}")
|
| 31 |
+
return False
|
| 32 |
+
except Exception as e:
|
| 33 |
+
print(f"❌ Connection failed: {e}")
|
| 34 |
+
return False
|
| 35 |
+
|
| 36 |
+
if __name__ == "__main__":
|
| 37 |
+
# Get args: python trigger_cloud.py --limit 10 --project p3
|
| 38 |
+
limit = 15
|
| 39 |
+
project = "p3"
|
| 40 |
+
|
| 41 |
+
if "--limit" in sys.argv:
|
| 42 |
+
idx = sys.argv.index("--limit")
|
| 43 |
+
if idx + 1 < len(sys.argv):
|
| 44 |
+
limit = int(sys.argv[idx + 1])
|
| 45 |
+
|
| 46 |
+
if "--project" in sys.argv:
|
| 47 |
+
idx = sys.argv.index("--project")
|
| 48 |
+
if idx + 1 < len(sys.argv):
|
| 49 |
+
project = sys.argv[idx + 1]
|
| 50 |
+
|
| 51 |
+
print(f"🚀 Triggering cloud processing: {project}, limit={limit}")
|
| 52 |
+
trigger_bundler(limit, project)
|