Arabic-first semantic search application for hadith collections, with optional Gemini-powered analysis.
- Arabic UI focused on fast discovery of relevant hadiths.
- TF-IDF semantic retrieval with per-collection caching.
- Resilient remote loading (retry + graceful fallback on API errors).
- Safe HTML rendering for external/API/LLM content.
- Modern branded UI (
Khalfa AI Solutions) with responsive layout. - Search history and quick-topic shortcuts.
- Python 3.10+
- Streamlit
- scikit-learn
- requests
- Google GenAI SDK (
google-genai)
app.py: Streamlit app and UI flow.hadith_core.py: Core logic (API loading, parsing, TF-IDF bundle, escaping).tests/test_hadith_core.py: Unit tests for core behavior.requirements.txt: Runtime dependencies.
pip install -r requirements.txtstreamlit run app.pyDefault URL:
http://localhost:8501
You can configure the Gemini API key in either way:
- In-app sidebar input field.
- Environment variable (recommended):
$env:GEMINI_API_KEY="YOUR_GEMINI_API_KEY"
streamlit run app.pyPersistent on Windows:
setx GEMINI_API_KEY "YOUR_GEMINI_API_KEY"Open a new terminal after setx.
The app handles 429 RESOURCE_EXHAUSTED with:
- Friendly error messages.
- Temporary cooldown using retry delay when available.
- Clear guidance for billing/quota issues.
If your project shows limit: 0, update quota/billing or use another project key.
Run unit tests:
python -m unittest discover -s tests -p "test_*.py"If present, the app auto-loads brand images from:
assets/khalfa-brand.pngassets/khalfa-logo.pngassets/brand-khalfa.pngkhalfa-brand.pngkhalfa-logo.png
- Do not hardcode API keys in source files.
- Rotate any key that has been shared in chat/screenshots.
Add your preferred license (MIT/Apache-2.0/etc.) in a LICENSE file.