""" FastAPI backend for humanize-e Developed by Mike Elistra (Mike Koci) Kaggle Training Notebook: https://www.kaggle.com/code/mick009/notebook9c4e543da9 Endpoints: - POST /humanize - Humanize text (JSON: {"text": "...", "temperature": 0.8}) - GET / - Web UI - GET /health - Health check """ import os from contextlib import asynccontextmanager from fastapi import FastAPI, HTTPException from fastapi.responses import HTMLResponse from pydantic import BaseModel import uvicorn # Load .env if present from dotenv import load_dotenv load_dotenv() from model import HumanizeModel model: HumanizeModel | None = None @asynccontextmanager async def lifespan(app: FastAPI): global model print("[humanize-e] Starting up...") model = HumanizeModel() print(f"[humanize-e] Model loaded: {model._loaded}") yield print("[humanize-e] Shutting down...") app = FastAPI( title="humanize-e API", description="Humanize AI-generated text with a QLoRA fine-tuned Qwen2.5-3B", version="1.0.0", lifespan=lifespan, ) class HumanizeRequest(BaseModel): text: str temperature: float = 0.8 class HumanizeResponse(BaseModel): original: str humanized: str model: str # "qwen2.5-3b-lora" or "fallback" @app.get("/", response_class=HTMLResponse) async def root(): return """
Make AI texts sound more human