Initial scaffold: FastAPI backend + React frontend + Docker Compose
- Backend: FastAPI with SQLite, clip CRUD, health check - Frontend: React + Vite + TypeScript + Tailwind, dark theme - Components: Generator, Gallery, Player - Docker: Compose setup for backend + frontend - Architecture docs in Palace KB
This commit is contained in:
commit
a2bc785b14
23 files changed
+819
No files matched your search
@@ -0,0 +1,76 @@
|
||||
from fastapi import FastAPI, HTTPException
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import FileResponse, StreamingResponse
|
||||
from pathlib import Path
|
||||
import os
|
||||
|
||||
from models import GenerateRequest, GenerateResponse, ClipList
|
||||
from database import init_db, create_clip, get_clips, get_clip, delete_clip, update_clip_status
|
||||
|
||||
app = FastAPI(title="Lyria Studio", version="0.1.0")
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
CLIPS_DIR = Path(__file__).parent.parent / "data" / "clips"
|
||||
CLIPS_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup():
|
||||
await init_db()
|
||||
|
||||
@app.get("/api/health")
|
||||
async def health():
|
||||
return {"status": "ok", "version": "0.1.0"}
|
||||
|
||||
@app.post("/api/generate", response_model=GenerateResponse)
|
||||
async def generate(request: GenerateRequest):
|
||||
clip_id = await create_clip(request.prompt, request.model, request.duration)
|
||||
# TODO: T-003 — integrate Lyria API client
|
||||
return GenerateResponse(
|
||||
id=clip_id,
|
||||
status="generating",
|
||||
message="Clip generation started. Check back for status."
|
||||
)
|
||||
|
||||
@app.get("/api/clips", response_model=ClipList)
|
||||
async def list_clips(limit: int = 50, offset: int = 0):
|
||||
clips = await get_clips(limit, offset)
|
||||
return ClipList(clips=clips, total=len(clips))
|
||||
|
||||
@app.get("/api/clips/{clip_id}")
|
||||
async def get_clip_by_id(clip_id: str):
|
||||
clip = await get_clip(clip_id)
|
||||
if not clip:
|
||||
raise HTTPException(status_code=404, detail="Clip not found")
|
||||
return clip
|
||||
|
||||
@app.get("/api/clips/{clip_id}/audio")
|
||||
async def stream_audio(clip_id: str):
|
||||
clip = await get_clip(clip_id)
|
||||
if not clip:
|
||||
raise HTTPException(status_code=404, detail="Clip not found")
|
||||
file_path = CLIPS_DIR / clip["filename"]
|
||||
if not file_path.exists():
|
||||
raise HTTPException(status_code=404, detail="Audio file not found")
|
||||
return FileResponse(file_path, media_type="audio/mpeg", filename=clip["filename"])
|
||||
|
||||
@app.delete("/api/clips/{clip_id}")
|
||||
async def remove_clip(clip_id: str):
|
||||
clip = await get_clip(clip_id)
|
||||
if not clip:
|
||||
raise HTTPException(status_code=404, detail="Clip not found")
|
||||
file_path = CLIPS_DIR / clip["filename"]
|
||||
if file_path.exists():
|
||||
file_path.unlink()
|
||||
await delete_clip(clip_id)
|
||||
return {"deleted": True}
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
uvicorn.run(app, host="0.0.0.0", port=8000)
|
||||
Reference in new issue
Block a user