File size: 1,849 Bytes
19d6b8b
c244342
19d6b8b
c244342
 
 
19d6b8b
 
c244342
 
 
19d6b8b
 
c244342
19d6b8b
 
 
 
 
 
 
c244342
 
 
 
 
 
19d6b8b
c244342
 
 
 
 
 
19d6b8b
 
c244342
19d6b8b
 
 
 
 
c244342
19d6b8b
 
c244342
19d6b8b
 
c244342
 
 
19d6b8b
c244342
 
 
 
 
 
 
 
19d6b8b
c244342
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from fastapi import FastAPI, UploadFile, File, Form, HTTPException
from fastapi.responses import FileResponse, HTMLResponse, RedirectResponse
from fastapi.middleware.cors import CORSMiddleware
from pathlib import Path
import uvicorn
import os
from renderer import render_logo

ROOT = Path(__file__).resolve().parent.parent
FRONTEND = ROOT / "frontend"

app = FastAPI(title="Manim Logo Renderer")

# CORS (Spaces ve lokal için serbest)
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_methods=["*"],
    allow_headers=["*"],
)

# ---- Routes ----

@app.get("/", include_in_schema=False)
async def root():
    # Kök istekleri UI'ye yönlendir
    return RedirectResponse(url="/web")

@app.get("/web", response_class=HTMLResponse)
async def web():
    index = FRONTEND / "index.html"
    if not index.exists():
        raise HTTPException(status_code=404, detail="frontend/index.html not found")
    return index.read_text(encoding="utf-8")

@app.get("/health")
async def health():
    return {"ok": True}

@app.post("/render")
async def render(
    file: UploadFile = File(...),
    animation: str = Form(...),       # draw | fade | spin | bounce
    duration: float = Form(4.0),
    bg_color: str = Form("#111111"),
    quality: str = Form("m"),         # l|m|h|u
):
    try:
        out_path = await render_logo(file, animation, duration, bg_color, quality)
    except ValueError as e:
        raise HTTPException(status_code=400, detail=str(e))
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"Render failed: {e}")

    # MP4 döndür
    return FileResponse(
        path=out_path,
        media_type="video/mp4",
        filename="logo_animation.mp4",
    )

if __name__ == "__main__":
    port = int(os.environ.get("PORT", "7860"))
    uvicorn.run("app:app", host="0.0.0.0", port=port)