# TranslateGemma Quick Start

Fast guide to test translation with Google's TranslateGemma 4B model on Modal.

---

## 1. Install Modal

```bash
pip install modal
```

## 2. Configure Modal Token

Get your token from https://modal.com/settings

```bash
modal token set --token-id YOUR_TOKEN_ID --token-secret YOUR_TOKEN_SECRET
```

## 3. Run Test

```bash
cd backend-app/modal-service
modal run gemmatranslate_service.py
```

### First Run (with model download)
- Downloads ~10GB model (one-time, 5-10 minutes)
- Model cached in Modal Volume for future use
- Translation takes ~40-60 seconds total

### Subsequent Runs (from cache)
- Loads model from cache (~1-2 seconds)
- Translation takes ~5-10 seconds total

---

## Expected Output

```
======================================================================
  TranslateGemma 4B Translation Test
======================================================================

📝 Input text:
   The quick brown fox jumps over the lazy dog...

🌐 Translation: en -> es

📦 Checking model cache...
✅ Model cached (9876.5 MB)
   Expected time: 5-10 seconds

🔄 Starting translation...

======================================================================
  Translation Results
======================================================================

✅ Translation successful!

📝 Original:
   The quick brown fox jumps over the lazy dog...

🌐 Translated:
   El rápido zorro marrón salta sobre el perro perezoso...

📊 Metrics:
   Tokens used: 142
   Processing time (server): 7500ms
   Total time (with network): 8200ms
   Model: google/translategemma-4b-it

======================================================================
  Test completed successfully! ✅
======================================================================
```

---

## Alternative: Use Python Test Script

More comprehensive testing with validation:

```bash
python test_translation.py
```

This includes:
- ✅ Cache status check
- ✅ Translation test
- ✅ Result validation
- ✅ Cost estimation
- ✅ Performance metrics

---

## Troubleshooting

**Error: "Modal token not configured"**
```bash
modal token set --token-id XXX --token-secret YYY
```

**First run is slow?**
- Normal! Downloading 10GB model
- Subsequent runs are 5-8x faster

**Out of memory?**
- Model needs ~20GB memory
- Modal may need to scale up GPU instance

---

## Next Steps

1. ✅ Test with custom text (edit `test_translation.py`)
2. ✅ Deploy as web service: `modal deploy gemmatranslate_service.py`
3. ✅ Integrate with backend API (update `.env`)
4. ✅ Monitor in Modal dashboard: https://modal.com/apps

---

## Support

- Full guide: See `TESTING.md`
- Modal docs: https://modal.com/docs
- Model info: https://huggingface.co/google/translategemma-4b-it
