Spaces:
Running on Zero
Running on Zero
Download api/main.py from omargam220/PlotCraft: direct link, hf CLI and curl.
- Browser
- Download file 1.04 kB
-
https://huggingface.co/spaces/omargam220/PlotCraft/resolve/main/api/main.py
- Command line
-
hf download hf://spaces/omargam220/PlotCraft/api/main.py
-
curl -L -o main.py https://huggingface.co/spaces/omargam220/PlotCraft/resolve/main/api/main.py
1.04 kB
| """FastAPI interface for the PlotCraft generation service.""" | |
| from fastapi import FastAPI, HTTPException | |
| from pydantic import BaseModel, Field | |
| from src.plotcraft.service import generate_plot_code | |
| app = FastAPI( | |
| title="PlotCraft API", | |
| description="Generate Python visualization code from natural language.", | |
| version="0.1.0", | |
| ) | |
| class GenerationRequest(BaseModel): | |
| prompt: str = Field(min_length=1, max_length=2000) | |
| class GenerationResponse(BaseModel): | |
| generated_code: str | |
| def health() -> dict[str, str]: | |
| return {"status": "healthy"} | |
| def generate(request: GenerationRequest) -> GenerationResponse: | |
| try: | |
| code = generate_plot_code(request.prompt) | |
| except ValueError as error: | |
| raise HTTPException(status_code=400, detail=str(error)) from error | |
| except RuntimeError as error: | |
| raise HTTPException(status_code=503, detail=str(error)) from error | |
| return GenerationResponse(generated_code=code) | |