CoolFace
Apppublic

MdSourav76046/TextCorrectionModel

sourceHugging Faceupdated 11mo agoView on Hugging Face
0likes
App README

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

bash
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:

bash
export MODEL_PATH="./gpu_base_model2"

3. Run the Server

Local Development:
bash
python main.py

Or using uvicorn directly:

bash
uvicorn main:app --reload --host 0.0.0.0 --port 8000

The API will be available at: http://localhost:8000

4. Test the API

bash
# 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:

json
{
  "status": "healthy",
  "model_loaded": true,
  "device": "cuda"
}

POST /correct

Correct text using the trained model.

Request:

json
{
  "text": "helo wrld this is a test"
}

Response:

json
{
  "corrected_text": "hello world this is a test",
  "processing_time": 0.45
}

๐ŸŒ Deployment Options

Option 1: Hugging Face Spaces (Free) - Recommended

  1. 1.Create a new Space at https://huggingface.co/new-space
  2. 2.Name: your-username-text-correction
  3. 3.SDK: Docker
  4. 4.License: MIT (or Apache 2.0)
  5. 5.Click "Create Space"
  1. 1.Upload files:
  2. 2.Upload all files from this directory
  3. 3.Upload your gpu_base_model2/ folder
  1. 1.Your API will be live at:
   https://your-username-text-correction.hf.space/correct

Option 2: Render (Free tier available)

  1. 1.Create a new Web Service
  2. 2.Connect your GitHub repository
  3. 3.Set build command: pip install -r requirements.txt
  4. 4.Set start command: uvicorn main:app --host 0.0.0.0 --port $PORT
  5. 5.Deploy

Option 3: Railway (Free tier available)

  1. 1.Create a new project
  2. 2.Add a service from GitHub
  3. 3.Railway will auto-detect the Python app
  4. 4.Set environment variable MODEL_PATH if needed
  5. 5.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:

  1. 1.Add authentication to your API endpoints
  2. 2.Set proper CORS origins (not *)
  3. 3.Add rate limiting
  4. 4.Use HTTPS
  5. 5.Keep your API key secure

๐Ÿ› Troubleshooting

Model not loading

  • โ€”Check that gpu_base_model2 directory exists
  • โ€”Verify all model files are present
  • โ€”Check console logs for specific errors

Out of memory

  • โ€”Reduce max_length in the generate function
  • โ€”Use smaller batch sizes
  • โ€”Consider using CPU instead of GPU

Slow inference

  • โ€”Use GPU if available
  • โ€”Reduce num_beams parameter
  • โ€”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:

  1. 1.User takes/selects an image
  2. 2.OCR extracts text from the image
  3. 3.Extracted text is sent to this API
  4. 4.API corrects the text using the trained model
  5. 5.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.