Spaces:
Sleeping
Sleeping
File size: 563 Bytes
ea0af80 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
from fastapi import FastAPI, HTTPException
from model import generate_code
app = FastAPI()
@app.get("/")
def home():
return {"message": "Code Generation API is running!"}
@app.post("/generate")
def generate(prompt: str, max_tokens: int = 256):
if not prompt:
raise HTTPException(status_code=400, detail="Prompt cannot be empty.")
try:
code = generate_code(prompt, max_tokens)
return {"generated_code": code}
except Exception as e:
raise HTTPException(status_code=500, detail=f"Internal Server Error: {str(e)}")
|