A lightweight web app for translating text between English and South Africa's local languages, powered by Hugging Face's open-source AI models and built with Python.
# Mzansi Translator 🇿🇦
I built this Streamlit app to make translating between South Africa's local languages. It's a simple web app that lets you pick a source and target language from all 9 of our official languages and translates your text in a couple of seconds. The app is coded in Python using Streamlit for the interface, connected to Hugging Face's Inference API for the actual translation.
## 🔥 What It Does
- **Language Selection:** Pick any "from" and "to" language out of English, isiZulu, isiXhosa, Afrikaans, Sepedi, Sesotho, Setswana, Xitsonga, and Siswati using two dropdowns.
- **Text Input:** Type or paste the text you want translated into a text area.
- **Translate Button:** Sends your text to the model and displays the clean, translated result, no extra notes or explanations, just the translation.
- **Custom Styling:** A warm, poster-inspired theme with a South African flag stripe, custom fonts (Anton + Montserrat), and a dark charcoal/gold color palette built entirely with custom CSS injected into Streamlit.
---
## đź§ What I Learned Doing This
Instead of just wiring up an API call and calling it done, I wanted to actually understand how each piece worked. Here is what I learned:
### 🔑 Choosing `InferenceClient` over the router endpoint
For an earlier project I called Hugging Face's hosted models through the raw router URL with `requests`, building the payload and headers manually:
```python
HF_TOKEN = st.secrets["HF_TOKEN"]
API_URL = "
router.huggingface.co"
HEADERS = {"Authorization": f"Bearer {HF_TOKEN}"}
payload = {
"inputs": text_input,
"parameters": {"max_length": max_len, "min_length": min_len},
}
response = requests.post(API_URL, headers=HEADERS, json=payload, timeout=60)
response.raise_for_status()
result = response.json()
summary = result[0]["summary_text"]
```
For this project, I ran into trouble getting that same route to reliably fetch the model I wanted, requests to it kept breachi …