Spaces:
Runtime error
title: Text Correction API
emoji: π§
colorFrom: blue
colorTo: purple
sdk: docker
sdk_version: 1.0.0
app_file: app.py
pinned: false
Text Correction API Server
This is the server-side API for text correction using your trained model.
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π Setup
1. Install Dependencies
pip install -r requirements.txt
2. Set Model Path
Make sure your trained model is in the gpu_base_model2 directory, or set the MODEL_PATH environment variable:
export MODEL_PATH="./gpu_base_model2"
3. Run the Server
Local Development:
python main.py
Or using uvicorn directly:
uvicorn main:app --reload --host 0.0.0.0 --port 8000
The API will be available at: http://localhost:8000
4. Test the API
# Health check
curl http://localhost:8000/health
# Correct text
curl -X POST http://localhost:8000/correct \
-H "Content-Type: application/json" \
-d '{"text": "helo wrld this is a test"}'
π‘ API Endpoints
GET /health
Check if the API and model are ready.
Response:
{
"status": "healthy",
"model_loaded": true,
"device": "cuda"
}
POST /correct
Correct text using the trained model.
Request:
{
"text": "helo wrld this is a test"
}
Response:
{
"corrected_text": "hello world this is a test",
"processing_time": 0.45
}
π Deployment Options
Option 1: Hugging Face Spaces (Free) - Recommended
Create a new Space at https://huggingface.co/new-space
- Name:
your-username-text-correction - SDK: Docker
- License: MIT (or Apache 2.0)
- Click "Create Space"
- Name:
Upload files:
- Upload all files from this directory
- Upload your
gpu_base_model2/folder
Your API will be live at:
https://your-username-text-correction.hf.space/correct
Option 2: Render (Free tier available)
- Create a new Web Service
- Connect your GitHub repository
- Set build command:
pip install -r requirements.txt - Set start command:
uvicorn main:app --host 0.0.0.0 --port $PORT - Deploy
Option 3: Railway (Free tier available)
- Create a new project
- Add a service from GitHub
- Railway will auto-detect the Python app
- Set environment variable
MODEL_PATHif needed - Deploy
Option 4: AWS/GCP/Azure
For production deployments with more control.
βοΈ Environment Variables
MODEL_PATH: Path to your trained model (default:./gpu_base_model2)PORT: Server port (default:8000)
π Security Notes
β οΈ Important for Production:
- Add authentication to your API endpoints
- Set proper CORS origins (not
*) - Add rate limiting
- Use HTTPS
- Keep your API key secure
π Troubleshooting
Model not loading
- Check that
gpu_base_model2directory exists - Verify all model files are present
- Check console logs for specific errors
Out of memory
- Reduce
max_lengthin the generate function - Use smaller batch sizes
- Consider using CPU instead of GPU
Slow inference
- Use GPU if available
- Reduce
num_beamsparameter - Use quantization for faster inference
π Usage
This API is designed to be called from an iOS app for correcting OCR text. The typical flow is:
- User takes/selects an image
- OCR extracts text from the image
- Extracted text is sent to this API
- API corrects the text using the trained model
- Corrected text is returned to the app
π€ Contributing
This is a private project for text correction. For questions or issues, please contact the project owner.