Spaces:
Sleeping
Sleeping
Commit
·
bdde028
0
Parent(s):
init project
Browse files- .gitignore +145 -0
- app/__init__.py +0 -0
- app/main.py +22 -0
- app/models.py +4 -0
- app/utils.py +7 -0
- requirements.txt +7 -0
- runserver.py +23 -0
.gitignore
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Python
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.py[cod]
|
| 4 |
+
*$py.class
|
| 5 |
+
*.so
|
| 6 |
+
.Python
|
| 7 |
+
build/
|
| 8 |
+
develop-eggs/
|
| 9 |
+
dist/
|
| 10 |
+
downloads/
|
| 11 |
+
eggs/
|
| 12 |
+
.eggs/
|
| 13 |
+
lib/
|
| 14 |
+
lib64/
|
| 15 |
+
parts/
|
| 16 |
+
sdist/
|
| 17 |
+
var/
|
| 18 |
+
wheels/
|
| 19 |
+
share/python-wheels/
|
| 20 |
+
*.egg-info/
|
| 21 |
+
.installed.cfg
|
| 22 |
+
*.egg
|
| 23 |
+
MANIFEST
|
| 24 |
+
|
| 25 |
+
# PyInstaller
|
| 26 |
+
*.manifest
|
| 27 |
+
*.spec
|
| 28 |
+
|
| 29 |
+
# Installer logs
|
| 30 |
+
pip-log.txt
|
| 31 |
+
pip-delete-this-directory.txt
|
| 32 |
+
|
| 33 |
+
# Unit test / coverage reports
|
| 34 |
+
htmlcov/
|
| 35 |
+
.tox/
|
| 36 |
+
.nox/
|
| 37 |
+
.coverage
|
| 38 |
+
.coverage.*
|
| 39 |
+
.cache
|
| 40 |
+
nosetests.xml
|
| 41 |
+
coverage.xml
|
| 42 |
+
*.cover
|
| 43 |
+
*.py,cover
|
| 44 |
+
.hypothesis/
|
| 45 |
+
.pytest_cache/
|
| 46 |
+
cover/
|
| 47 |
+
|
| 48 |
+
# Virtual environments
|
| 49 |
+
.env
|
| 50 |
+
.venv
|
| 51 |
+
env/
|
| 52 |
+
venv/
|
| 53 |
+
ENV/
|
| 54 |
+
env.bak/
|
| 55 |
+
venv.bak/
|
| 56 |
+
|
| 57 |
+
# IDEs
|
| 58 |
+
.vscode/
|
| 59 |
+
.idea/
|
| 60 |
+
*.swp
|
| 61 |
+
*.swo
|
| 62 |
+
*~
|
| 63 |
+
|
| 64 |
+
# OS
|
| 65 |
+
.DS_Store
|
| 66 |
+
.DS_Store?
|
| 67 |
+
._*
|
| 68 |
+
.Spotlight-V100
|
| 69 |
+
.Trashes
|
| 70 |
+
ehthumbs.db
|
| 71 |
+
Thumbs.db
|
| 72 |
+
|
| 73 |
+
# Application specific
|
| 74 |
+
/sandbox/*
|
| 75 |
+
!/sandbox/.gitkeep
|
| 76 |
+
/logs/*
|
| 77 |
+
!/logs/.gitkeep
|
| 78 |
+
/examples/*
|
| 79 |
+
!/examples/.gitkeep
|
| 80 |
+
|
| 81 |
+
# Environment variables
|
| 82 |
+
.env
|
| 83 |
+
.env.local
|
| 84 |
+
.env.development.local
|
| 85 |
+
.env.test.local
|
| 86 |
+
.env.production.local
|
| 87 |
+
|
| 88 |
+
# API keys and secrets
|
| 89 |
+
*.key
|
| 90 |
+
*.pem
|
| 91 |
+
secrets/
|
| 92 |
+
config/secrets.yml
|
| 93 |
+
|
| 94 |
+
# Temporary files
|
| 95 |
+
*.tmp
|
| 96 |
+
*.temp
|
| 97 |
+
temp/
|
| 98 |
+
tmp/
|
| 99 |
+
|
| 100 |
+
# Upload files
|
| 101 |
+
uploads/
|
| 102 |
+
upload/
|
| 103 |
+
|
| 104 |
+
# Database files
|
| 105 |
+
*.db
|
| 106 |
+
*.sqlite
|
| 107 |
+
*.sqlite3
|
| 108 |
+
|
| 109 |
+
# Docker
|
| 110 |
+
docker-compose.override.yml
|
| 111 |
+
.dockerignore
|
| 112 |
+
|
| 113 |
+
# Jupyter Notebook
|
| 114 |
+
.ipynb_checkpoints
|
| 115 |
+
|
| 116 |
+
# pyenv
|
| 117 |
+
.python-version
|
| 118 |
+
|
| 119 |
+
# pipenv
|
| 120 |
+
Pipfile.lock
|
| 121 |
+
|
| 122 |
+
# Poetry
|
| 123 |
+
poetry.lock
|
| 124 |
+
|
| 125 |
+
# Celery
|
| 126 |
+
celerybeat-schedule
|
| 127 |
+
celerybeat.pid
|
| 128 |
+
|
| 129 |
+
# SageMath parsed files
|
| 130 |
+
*.sage.py
|
| 131 |
+
|
| 132 |
+
# Spyder project settings
|
| 133 |
+
.spyderproject
|
| 134 |
+
.spyproject
|
| 135 |
+
|
| 136 |
+
# Rope project settings
|
| 137 |
+
.ropeproject
|
| 138 |
+
|
| 139 |
+
# mkdocs documentation
|
| 140 |
+
/site
|
| 141 |
+
|
| 142 |
+
# mypy
|
| 143 |
+
.mypy_cache/
|
| 144 |
+
.dmypy.json
|
| 145 |
+
dmypy.json
|
app/__init__.py
ADDED
|
File without changes
|
app/main.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException, status, Request
|
| 2 |
+
from models import TaskRequest
|
| 3 |
+
from utils import validate_secret
|
| 4 |
+
app = FastAPI()
|
| 5 |
+
|
| 6 |
+
@app.post("/handle-task")
|
| 7 |
+
async def handle_task(request: TaskRequest):
|
| 8 |
+
if not validate_secret(request.secret):
|
| 9 |
+
raise HTTPException(
|
| 10 |
+
status_code=status.HTTP_401_UNAUTHORIZED,
|
| 11 |
+
detail="Invalid secret",
|
| 12 |
+
headers={"WWW-Authenticate": "Bearer"},
|
| 13 |
+
)
|
| 14 |
+
# Proceed with further task processing here
|
| 15 |
+
return {"status": "success"}
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
@app.get("/")
|
| 21 |
+
def read_root():
|
| 22 |
+
return {"Hello": "World"}
|
app/models.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pydantic import BaseModel
|
| 2 |
+
|
| 3 |
+
class TaskRequest(BaseModel):
|
| 4 |
+
secret: str
|
app/utils.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
API_SECRET = os.getenv("API_SECRET", "shamil")
|
| 3 |
+
|
| 4 |
+
def validate_secret(secret: str) -> bool:
|
| 5 |
+
# Constant-time comparison to prevent timing attacks
|
| 6 |
+
from hmac import compare_digest
|
| 7 |
+
return compare_digest(secret, API_SECRET)
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi==0.104.1
|
| 2 |
+
uvicorn[standard]==0.24.0
|
| 3 |
+
python-multipart==0.0.6
|
| 4 |
+
pydantic
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
python-dotenv==1.0.0
|
runserver.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Server startup script for the LLM Code Deployment API.
|
| 4 |
+
Starts FastAPI backend on port 7860, compatible with Hugging Face Spaces Docker deployments.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import uvicorn
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
|
| 10 |
+
if __name__ == "__main__":
|
| 11 |
+
# If your app needs to store temporary files or logs, ensure directories are created here.
|
| 12 |
+
# Path("sandbox").mkdir(exist_ok=True) # Optional: for generated apps/files
|
| 13 |
+
# Path("logs").mkdir(exist_ok=True) # Optional: for logging
|
| 14 |
+
# Path("examples").mkdir(exist_ok=True) # Optional: for usage examples
|
| 15 |
+
|
| 16 |
+
# Start the FastAPI app; Hugging Face Spaces requires port 7860
|
| 17 |
+
uvicorn.run(
|
| 18 |
+
"app.main:app", # Your FastAPI entrypoint (update path if needed)
|
| 19 |
+
host="0.0.0.0",
|
| 20 |
+
port=7860,
|
| 21 |
+
reload=False,
|
| 22 |
+
log_level="info"
|
| 23 |
+
)
|