muhammadjalaludin
Implement service layers for backup, model management, file handling, tokenization, and training
1424118 Download api/predict.py from kota101/ta_ml: direct link, hf CLI and curl.
- Browser
- Download file 1.91 kB
-
https://huggingface.co/spaces/kota101/ta_ml/resolve/main/api/predict.py
- Command line
-
hf download hf://spaces/kota101/ta_ml/api/predict.py
-
curl -L -o predict.py https://huggingface.co/spaces/kota101/ta_ml/resolve/main/api/predict.py
1.91 kB
| # ta_ml/api/predict.py | |
| """ | |
| API endpoint for model prediction. | |
| """ | |
| import logging | |
| from fastapi import APIRouter, Depends, HTTPException | |
| from api.dependencies import get_prediction_service | |
| from models.api import PredictRequest, PredictResponse | |
| from services.prediction_service import PredictionService | |
| logger = logging.getLogger(__name__) | |
| router = APIRouter(prefix="/predict", tags=["Prediction"]) | |
| def predict_transaction( | |
| request: PredictRequest, | |
| prediction_service: PredictionService = Depends(get_prediction_service) | |
| ): | |
| try: | |
| result = prediction_service.predict(request.text) | |
| return PredictResponse(**result) | |
| except ValueError as e: | |
| logger.warning(f"Prediction failed due to invalid input: {e}") | |
| raise HTTPException(status_code=400, detail=str(e)) | |
| except Exception as e: | |
| logger.error( | |
| f"An unexpected error occurred during prediction: {e}", exc_info=True) | |
| raise HTTPException( | |
| status_code=500, detail="An internal error occurred during prediction." | |
| ) | |