Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -258,115 +258,86 @@ async def health_check():
|
|
| 258 |
}
|
| 259 |
|
| 260 |
|
| 261 |
-
# Gradio UI for
|
| 262 |
with gr.Blocks(title="code-chef ModelOps Trainer") as demo:
|
| 263 |
gr.Markdown(
|
| 264 |
"""
|
| 265 |
# 🏗️ code-chef ModelOps Training Service
|
| 266 |
|
| 267 |
AutoTrain-powered fine-tuning for code-chef agents.
|
| 268 |
-
|
| 269 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
)
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
job_id_input = gr.Textbox(
|
| 286 |
-
label="Job ID", placeholder="job_20251210_123456_feature_dev"
|
| 287 |
-
)
|
| 288 |
-
check_btn = gr.Button("Check Status")
|
| 289 |
-
status_output = gr.JSON(label="Job Status")
|
| 290 |
-
|
| 291 |
-
with gr.Tab("API Documentation"):
|
| 292 |
-
gr.Markdown(
|
| 293 |
-
"""
|
| 294 |
-
## REST API Endpoints
|
| 295 |
-
|
| 296 |
-
### POST /train
|
| 297 |
-
Submit a new training job
|
| 298 |
-
|
| 299 |
-
```bash
|
| 300 |
-
curl -X POST https://YOUR-SPACE.hf.space/train \\
|
| 301 |
-
-H "Content-Type: application/json" \\
|
| 302 |
-
-d '{
|
| 303 |
-
"agent_name": "feature_dev",
|
| 304 |
-
"base_model": "Qwen/Qwen2.5-Coder-7B",
|
| 305 |
-
"dataset_csv": "<base64-encoded-csv>",
|
| 306 |
-
"training_method": "sft",
|
| 307 |
-
"demo_mode": false
|
| 308 |
-
}'
|
| 309 |
-
```
|
| 310 |
-
|
| 311 |
-
### GET /status/{job_id}
|
| 312 |
-
Get training job status
|
| 313 |
-
|
| 314 |
-
```bash
|
| 315 |
-
curl https://YOUR-SPACE.hf.space/status/job_20251210_123456_feature_dev
|
| 316 |
-
```
|
| 317 |
-
|
| 318 |
-
### GET /health
|
| 319 |
-
Health check
|
| 320 |
-
|
| 321 |
-
```bash
|
| 322 |
-
curl https://YOUR-SPACE.hf.space/health
|
| 323 |
-
```
|
| 324 |
-
"""
|
| 325 |
-
)
|
| 326 |
-
|
| 327 |
-
# Event handlers
|
| 328 |
-
def submit_job(agent, model, dataset, method, demo):
|
| 329 |
-
if not dataset:
|
| 330 |
-
return {"error": "Dataset file required"}
|
| 331 |
-
|
| 332 |
-
# Read CSV and encode
|
| 333 |
-
import base64
|
| 334 |
-
|
| 335 |
-
csv_content = dataset.read()
|
| 336 |
-
encoded_csv = base64.b64encode(csv_content).decode()
|
| 337 |
-
|
| 338 |
-
request = TrainingRequest(
|
| 339 |
-
agent_name=agent,
|
| 340 |
-
base_model=model,
|
| 341 |
-
dataset_csv=encoded_csv,
|
| 342 |
-
training_method=method,
|
| 343 |
-
demo_mode=demo,
|
| 344 |
-
)
|
| 345 |
-
|
| 346 |
-
# Submit via API
|
| 347 |
-
import requests
|
| 348 |
-
|
| 349 |
-
response = requests.post("http://localhost:7860/train", json=request.dict())
|
| 350 |
-
return response.json()
|
| 351 |
-
|
| 352 |
-
def check_status(job_id):
|
| 353 |
-
import requests
|
| 354 |
-
|
| 355 |
-
response = requests.get(f"http://localhost:7860/status/{job_id}")
|
| 356 |
-
return response.json()
|
| 357 |
-
|
| 358 |
-
submit_btn.click(
|
| 359 |
-
fn=submit_job,
|
| 360 |
-
inputs=[agent_name, base_model, dataset_file, training_method, demo_mode],
|
| 361 |
-
outputs=output_status,
|
| 362 |
)
|
| 363 |
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
# Mount Gradio app to FastAPI
|
| 367 |
-
app = gr.mount_gradio_app(app, demo, path="/")
|
| 368 |
|
| 369 |
if __name__ == "__main__":
|
| 370 |
import uvicorn
|
| 371 |
|
| 372 |
-
uvicorn.run(
|
|
|
|
| 258 |
}
|
| 259 |
|
| 260 |
|
| 261 |
+
# Gradio UI for API documentation
|
| 262 |
with gr.Blocks(title="code-chef ModelOps Trainer") as demo:
|
| 263 |
gr.Markdown(
|
| 264 |
"""
|
| 265 |
# 🏗️ code-chef ModelOps Training Service
|
| 266 |
|
| 267 |
AutoTrain-powered fine-tuning for code-chef agents.
|
| 268 |
+
|
| 269 |
+
## API Status
|
| 270 |
+
✅ Service is running
|
| 271 |
+
|
| 272 |
+
## Quick Test
|
| 273 |
+
```bash
|
| 274 |
+
curl https://alextorelli-code-chef-modelops-trainer.hf.space/health
|
| 275 |
+
```
|
| 276 |
+
|
| 277 |
+
## REST API Endpoints
|
| 278 |
+
|
| 279 |
+
### POST /train
|
| 280 |
+
Submit a new training job
|
| 281 |
+
|
| 282 |
+
```bash
|
| 283 |
+
curl -X POST https://alextorelli-code-chef-modelops-trainer.hf.space/train \\
|
| 284 |
+
-H "Content-Type: application/json" \\
|
| 285 |
+
-d '{
|
| 286 |
+
"dataset": "<base64-encoded-csv>",
|
| 287 |
+
"base_model": "microsoft/Phi-3-mini-4k-instruct",
|
| 288 |
+
"project_name": "codechef-feature-dev",
|
| 289 |
+
"is_demo": true,
|
| 290 |
+
"text_column": "text",
|
| 291 |
+
"response_column": "response"
|
| 292 |
+
}'
|
| 293 |
+
```
|
| 294 |
+
|
| 295 |
+
### GET /status/{job_id}
|
| 296 |
+
Get training job status
|
| 297 |
+
|
| 298 |
+
```bash
|
| 299 |
+
curl https://alextorelli-code-chef-modelops-trainer.hf.space/status/job_xxx
|
| 300 |
+
```
|
| 301 |
+
|
| 302 |
+
### GET /health
|
| 303 |
+
Health check endpoint
|
| 304 |
+
|
| 305 |
+
Returns service status and configuration.
|
| 306 |
+
|
| 307 |
+
## Python Client
|
| 308 |
+
|
| 309 |
+
```python
|
| 310 |
+
from agent_orchestrator.agents.infrastructure.modelops.training import ModelOpsTrainerClient
|
| 311 |
+
|
| 312 |
+
client = ModelOpsTrainerClient()
|
| 313 |
+
|
| 314 |
+
# Submit job
|
| 315 |
+
job = client.submit_training_job(
|
| 316 |
+
csv_data="text,response\\ncode,output",
|
| 317 |
+
base_model="microsoft/Phi-3-mini-4k-instruct",
|
| 318 |
+
project_name="test-training",
|
| 319 |
+
is_demo=True
|
| 320 |
)
|
| 321 |
+
|
| 322 |
+
# Check status
|
| 323 |
+
status = client.get_job_status(job["job_id"])
|
| 324 |
+
```
|
| 325 |
+
|
| 326 |
+
## Model Presets
|
| 327 |
+
- **phi-3-mini**: 3.8B params, t4-small GPU ($0.75/hr)
|
| 328 |
+
- **codellama-7b**: 7B params, a10g-large GPU ($2.20/hr)
|
| 329 |
+
- **codellama-13b**: 13B params, a10g-large GPU ($2.20/hr)
|
| 330 |
+
|
| 331 |
+
## Training Modes
|
| 332 |
+
- **Demo**: 1 epoch, ~5 min, ~$0.50
|
| 333 |
+
- **Production**: 3 epochs, ~90 min, $3.50-$15
|
| 334 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
)
|
| 336 |
|
| 337 |
+
# Mount Gradio to root and FastAPI to /api
|
| 338 |
+
demo = gr.mount_gradio_app(app, demo, path="/")
|
|
|
|
|
|
|
| 339 |
|
| 340 |
if __name__ == "__main__":
|
| 341 |
import uvicorn
|
| 342 |
|
| 343 |
+
uvicorn.run(demo, host="0.0.0.0", port=7860)
|