Submission: Sunbird AI Assistant#11
Open
mwiin561 wants to merge 3 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🐦 Sunbird AI Assistant — Speak Local. by irwin mwiine
A Generative AI web application built on top of the Sunbird AI API. It takes English text or an English audio file, summarizes it, translates the summary into a chosen Ugandan local language, and generates a playable audio clip of the translation — all in one pipeline. Built with Python and Streamlit as part of the Sunbird AI Internship Assessment.
Live Demo: https://huggingface.co/spaces/ixmwiin3/sunbird-ai-assistant
🏗️ Architecture Overview
The application follows a linear 4-step pipeline:
Sunbird API Endpoints Used
POST /tasks/modal/sttPOST /tasks/sunflower_simplePOST /tasks/translatePOST /tasks/modal/tts🛠️ Local Setup
Prerequisites
Steps
1. Clone the repository
2. Create and activate a virtual environment
3. Install dependencies
4. Configure environment variables
Create a
.envfile in thesunbird-appfolder based on.env.example:Then open
.envand add your token:5. Run the app
The app will open at
http://localhost:8501.🔑 Environment Variables
SUNBIRD_API_TOKEN📁 Project Structure
🧪 Test Scripts
During development, every API endpoint was tested in isolation before being wired into the main pipeline. Each script in
backend/tests/targets a specific endpoint and prints the raw response so the exact field names and response structure could be confirmed before writing the client code.stt_test.pymodal_stt_test.pytranslation_test.py/tasks/translateworks and shows the correct response structuretts_test.py/tasks/modal/tts— returned 500 due to wrong speaker_idtts_test2.py/tasks/runpod/ttsas an alternative — timed out consistentlytts_test3.pysunflower_simple.pysum_test.pylanguage_test.py/tasks/language_idreturns{"language": "lug"}formatcheck_token.py🖥️ Usage
Text Input
Audio Upload
🚧 Development Challenges and How They Were Solved
Building this app involved a significant amount of trial and error with the Sunbird API. Here is an honest account of the obstacles encountered and how each one was resolved.
1. API token not loading in Streamlit context
Plain
load_dotenv()couldn't find the.envfile when Streamlit ran the app from a different working directory. Fixed by usingload_dotenv(dotenv_path=os.path.join(os.path.dirname(__file__), '..', '.env'))to resolve the path relative to the client file itself.2.
/tasks/summariseendpoint was deprecated and timing outThe original summarization endpoint consistently timed out after 60 seconds. After checking the API docs,
/tasks/sunflower_simplewas identified as the replacement. However, this endpoint required form data (data=) instead of JSON (json=), which caused 422 validation errors until the docs were read carefully.3. Sunflower model responding in Swahili
Even when given English input, the Sunflower model would sometimes respond in Swahili because Swahili is well-represented in its training data. Fixed by prepending
"You must respond in English only. Do not translate."to every summarization instruction.4. Wrong speaker_id causing 500 errors on TTS
The original code used
speaker_id=248which consistently returned a 500 server error. After checking the API docs example response which showedspeaker_id: 241, switching to 241 fixed the issue immediately.5.
/tasks/runpod/ttstiming outThe RunPod TTS endpoint timed out on every attempt. The Modal TTS endpoint at
/tasks/modal/ttswas used instead and worked reliably.6. STT rejecting audio files with 422 errors
The original STT call sent the file without a MIME type. The API couldn't determine the file format and rejected it. Fixed by using the tuple format
("filename.mp3", file_object, "audio/mpeg")in the files parameter.7. Audio binary file blocking Hugging Face deployment
A test audio file (
audio_test _0.mp3) that was committed to the repository blocked the push to Hugging Face Spaces because binary files are not allowed in Space repositories. Resolved by removing the file from git history usinggit filter-branch.💡 Ideas Explored and Their Limitations
Bidirectional translation (Local → English and Local → Local)
An attempt was made to support translating from local languages back to English, and between two local languages. The language detection endpoint (
/tasks/language_id) was integrated to auto-detect the input language. However, the Sunbird translation model only supports translation to or from English — direct local-to-local translation is not supported. A pivot-through-English approach was implemented but the Sunflower summarization model produced unreliable output when given local language text, sometimes responding in Swahili or a mix of languages. This feature was removed from the final version to keep the app reliable and predictable.Live microphone translation
A real-time push-to-talk feature was considered where the user could speak into their microphone and receive an instant translation. This is not feasible in Streamlit because Streamlit operates on a request-response model and does not support continuous audio streaming from the browser. This would require a proper WebRTC-based web application to implement correctly.
Audio duration check using actual duration
The assessment requires rejecting audio files longer than 5 minutes. The implementation uses file size as a proxy for duration (approximately 4.8MB for 5 minutes of 128kbps MP3) because checking actual duration requires
pydubandffmpeg. While ffmpeg is available on Hugging Face Spaces by default, it adds setup complexity. A proper duration check usingpydubis planned as a future improvement.🔧 Requirements
Built for the Sunbird AI Internship Assessment.