acarvalhofaktion
commited on
Commit
•
6c651c8
1
Parent(s):
55fc306
fix commit
Browse files- Dockerfile +15 -0
- autotrain/endpoints/__init__.py +0 -0
- autotrain/endpoints/autotrain.py +18 -0
- autotrain/main.py +30 -0
- autotrain/requirements.txt +3 -0
Dockerfile
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# syntax=docker/dockerfile:1
|
2 |
+
FROM python:3.11 AS base_image
|
3 |
+
|
4 |
+
WORKDIR /app
|
5 |
+
RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan bitbucket.org >> ~/.ssh/known_hosts
|
6 |
+
RUN --mount=type=ssh pip install -e git+ssh://git@bitbucket.org/faktionml/autotrain-advanced.git#egg=autotrain-advanced
|
7 |
+
|
8 |
+
FROM base_image
|
9 |
+
|
10 |
+
EXPOSE 7860
|
11 |
+
|
12 |
+
COPY . .
|
13 |
+
RUN pip install -r autotrain/requirements.txt
|
14 |
+
|
15 |
+
CMD ["python", "autotrain/main.py"]
|
autotrain/endpoints/__init__.py
ADDED
File without changes
|
autotrain/endpoints/autotrain.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import APIRouter, Request
|
2 |
+
import yaml
|
3 |
+
import os
|
4 |
+
|
5 |
+
|
6 |
+
router = APIRouter()
|
7 |
+
|
8 |
+
@router.post('/create_project')
|
9 |
+
async def create_project(request: Request):
|
10 |
+
parameters = await request.json()
|
11 |
+
with open('autotrain_config.yaml', 'w+') as ff:
|
12 |
+
yaml.dump(parameters, ff)
|
13 |
+
|
14 |
+
os.system("autotrain --config autotrain_config.yaml")
|
15 |
+
|
16 |
+
return {"status": "sucess", "message": "Project created successfully."}
|
17 |
+
|
18 |
+
|
autotrain/main.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""API endpoint code."""
|
2 |
+
import logging
|
3 |
+
|
4 |
+
import uvicorn
|
5 |
+
from fastapi import FastAPI, status
|
6 |
+
from endpoints import autotrain as autotrain_router
|
7 |
+
import logging
|
8 |
+
import sys
|
9 |
+
|
10 |
+
app = FastAPI()
|
11 |
+
app.include_router(autotrain_router.router, prefix="/autotrain")
|
12 |
+
|
13 |
+
logger = logging.getLogger(__name__)
|
14 |
+
logger.setLevel(logging.INFO)
|
15 |
+
stream_handler = logging.StreamHandler(sys.stdout)
|
16 |
+
log_formatter = logging.Formatter("%(asctime)s [%(processName)s: %(process)d] [%(threadName)s: %(thread)d] [%(levelname)s] %(name)s: %(message)s")
|
17 |
+
stream_handler.setFormatter(log_formatter)
|
18 |
+
logger.addHandler(stream_handler)
|
19 |
+
|
20 |
+
logger.info('API is starting up')
|
21 |
+
|
22 |
+
@app.get("/", status_code=status.HTTP_200_OK)
|
23 |
+
async def read_root():
|
24 |
+
message = f"Hello world! From FastAPI running on Uvicorn with Gunicorn"
|
25 |
+
logging.info(message)
|
26 |
+
return {"message": message}
|
27 |
+
|
28 |
+
|
29 |
+
if __name__ == '__main__':
|
30 |
+
uvicorn.run(app, host='0.0.0.0', port=7860)
|
autotrain/requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
fastapi==0.110.2
|
2 |
+
pyyaml==6.0.1
|
3 |
+
uvicorn==0.29.0
|