A simple RESTful API for accessing Gujarati language words and their definitions.
- Get all words with pagination
- Search for words by keyword
- Get specific word details by ID
- Get exact Gujarati word matches
- Get typeahead suggestions
- Get random words for practice
- Stream word and example audio
- Python 3.8 or later
- FastAPI
- Uvicorn
-
Clone the repository:
git clone https://github.com/yourusername/gujarati_api.git cd gujarati_api -
Install dependencies:
pip install -r requirements.txt -
Prepare your data:
- Place your Gujarati words JSON file in the
datadirectory - Ensure it's named
gujarati_words.json
- Place your Gujarati words JSON file in the
-
Run the application:
python main.py -
Open your browser and navigate to:
http://localhost:8000/docs
-
GET /api/v1/words- Get all words with pagination- Query parameters:
skip(optional): Number of items to skip (default: 0)limit(optional): Maximum number of items to return (default: 25, max: 500)
- Query parameters:
-
GET /api/v1/words/search- Search for words containing a keyword- Query parameters:
keyword(required): Keyword to search forskip(optional): Number of matching items to skip (default: 0)limit(optional): Maximum number of matching items to return (default: 25, max: 500)
- Query parameters:
-
GET /api/v1/words/suggest- Get typeahead suggestions- Query parameters:
keyword(required): Gujarati or romanized text to suggest fromlimit(optional): Maximum number of suggestions to return (default: 10, max: 100)
- Query parameters:
-
GET /api/v1/words/random- Get random words for practice or discovery- Query parameters:
limit(optional): Maximum number of random words to return (default: 10, max: 100)
- Query parameters:
-
GET /api/v1/words/count- Get the total number of word entries -
GET /api/v1/words/by-word/{word}- Get all entries matching a Gujarati word exactly -
GET /api/v1/words/{word_id}- Get a word by its ID -
GET /api/v1/audio/word/{word_id}- Get the audio file for a word -
GET /api/v1/audio/example/{word_id}- Get the audio file for an example sentence
Sikho should treat this API as its dictionary and audio layer:
- Use
idas the stable key for saved words, audio playback, dictation, and examples. - Use
word,ipa,romanization,definitions,example,example_romanization, andexample_translationfor word cards. - Use
word_audio_urlandexample_audio_urlinstead of parsingword_audioorexample_audiopaths. - Use
/words/suggestfor search/typeahead when adding words to My Words. - Use
/words/by-word/{word}when the Akshara Explorer needs dictionary entries for exact Gujarati text. - Keep akshara segmentation, matra labels, virama/conjunct detection, ra-form detection, and schwa-deletion teaching in Sikho's literacy layer.
The API uses the following data model for words:
{
"id": "0",
"word": "અકબંધ",
"ipa": "/\\k.b\\n.d˙\\/",
"romanization": "akbndh",
"definitions": [
{
"pos": "adj.",
"definition": "1. intact. 2. neither opened nor broken."
}
],
"example": "તેની ડાયરી અકબંધ હતી, કોઈએ તેને ખોલી ન હતી.",
"example_romanization": "teni dayri akbndh hti, koie tene kholi n hti.",
"example_translation": "His diary was intact, no one opened it.",
"example_audio": "audio/examples/0.mp3",
"word_audio": "audio/words/0.mp3",
"example_audio_url": "/api/v1/audio/example/0",
"word_audio_url": "/api/v1/audio/word/0",
"has_example_audio": true,
"has_word_audio": true
}The enhanced data includes:
- Cleaned and validated Gujarati words in Unicode
- Standardized part of speech tags
- Cleaned IPA pronunciations
- Phonetic pronunciations (in the ipa_alt field)
- Example sentences in Gujarati
The repository includes a script to enhance the Gujarati word data using AI:
- Cleans up and validates Gujarati words in Unicode format
- Validates and standardizes part of speech tags
- Cleans up and validates IPA pronunciations
- Converts alternative IPA to phonetic pronunciations
- Adds example sentences in Gujarati
- Uses web search to find examples when needed
- Anthropic API key (Claude)
- Tavily API key (for web searches)
-
Install the required dependencies:
pip install -r requirements.txt -
Run the enhancement script:
python enhance_gujarati_words.py -
The script will:
- Process words in batches
- Save intermediate results after each batch
- Create an enhanced version at
data/gujarati_words_enhanced.json
You can modify these parameters in the script:
batch_size: Number of words to process in each batch- For testing with a small subset, uncomment the line:
# items = items[:20]
The repository includes utilities to help you test and switch between different data files:
-
Test with a small subset:
python test_enhance_gujarati.pyThis processes only the first 3 words and saves the result to
data/test_enhanced_words.json. -
Verify enhanced data:
python verify_enhanced_data.pyThis checks if the enhanced data is compatible with the API models.
-
Switch between data files:
python switch_data_file.py --list # List all available data files python switch_data_file.py --test # Switch to test data python switch_data_file.py --enhanced # Switch to enhanced data python switch_data_file.py --original # Restore original dataThis allows you to easily test the API with different data files without permanently replacing the original data.
-
Example API usage:
python example_api_usage.pyThis demonstrates how to use the API with the enhanced data, showing how to access the example sentences and other fields.
-
Monitor enhancement progress:
python monitor_enhancement.pyThis provides a real-time monitor of the enhancement process, showing progress, statistics about examples, and estimated time remaining.
-
Analyze enhancements:
python analyze_enhancements.pyThis analyzes the differences between the original and enhanced data, providing statistics on changes, examples, and part of speech tags.
python analyze_enhancements.py --output analysis_results.jsonYou can also save the analysis results to a JSON file for further processing.
-
Run complete workflow:
python run_enhancement_workflow.pyThis runs the complete enhancement workflow in one command, including backup, enhancement, verification, and analysis.
python run_enhancement_workflow.py --testRun in test mode to process only a few words.
python run_enhancement_workflow.py --replaceReplace the original data file with the enhanced data after processing.
python run_enhancement_workflow.py --skip-report --skip-analysisSkip generating reports and analysis to speed up the process.
python run_enhancement_workflow.py --open-reportAutomatically open the HTML report in your browser after generation.
-
Clean up temporary files:
python cleanup.pyThis lists all temporary and backup files that can be cleaned up.
python cleanup.py --backups # Delete backup files python cleanup.py --temp # Delete temporary files python cleanup.py --all # Delete all backup and temporary files python cleanup.py --dry-run # Show what would be deleted without actually deleting -
Generate visual report:
python generate_report.pyThis generates an HTML report with charts and statistics comparing the original and enhanced data.
python generate_report.py --output custom_report.htmlYou can specify a custom output file for the report.
-
Open HTML report:
python open_report.py
This opens the generated HTML report in your default web browser.
python open_report.py --list
List all available report files and choose one to open.
python open_report.py --file custom_report.html
Open a specific report file.
- Run API with enhanced data:
python run_api_with_enhanced_data.py
This runs the API server with the enhanced data and opens the API documentation in your browser.
python run_api_with_enhanced_data.py --data test
Run the API with test data instead of enhanced data.
python run_api_with_enhanced_data.py --no-browser
Run the API without automatically opening the browser.
- All-in-one enhancement suite:
python gujarati_enhancement_suite.py
This runs the entire enhancement workflow from start to finish with a single command.
python gujarati_enhancement_suite.py --test --open-report --run-api
Run in test mode, open the report in browser, and start the API server after enhancement.
python gujarati_enhancement_suite.py --help
See all available options for customizing the enhancement process.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the Apache License - see the LICENSE file for details.