QuranicJar is a SwiftUI-based iOS application that predicts a user's emotion based on their input and provides a relevant Quranic verse for guidance and comfort. The app uses a Flask-based backend API powered by fine-tuned Natural Language Processing (NLP) BERT and RoBERTa models for emotion classification.
- Features
- File Description
- How it Works
- How to Run the Project
- Future Enhancements
- Contributions
- Acknowledgments
- License
- Emotion Prediction: Users can input their feelings, and the app predicts their emotion using a backend API.
- Supported Emotions: As for now, there are 4 supported emotions which are anger, fear, joy and sadness.
- Quranic Verse Recommendation: Based on the predicted emotion, the app provides a relevant Quranic verse for guidance.
- Bookmark Verse: Bookmark and filter your saved verses based on emotions.
- Search Verse: Search verses according to emotion types, Surah's name or translation keywords.
- Ensemble Model: Combines predictions from BERT and RoBERTa (NLP) models for improved accuracy.
- Loading Indicator: Displays a progress view while the emotion prediction is being processed.
-
QuranJarApp.swift
:- The main entry point of the iOS app.
-
ContentView.swift
:- The main screen where users can input their feelings, predict emotions, and view Quranic verses.
- Sends API requests to the Flask backend for emotion prediction.
-
WelcomeView.swift
:- The initial screen where users are greeted and asked to enter their name.
-
app.py
:- Flask-based backend API for emotion prediction.
- Uses fine-tuned BERT and RoBERTa models to classify emotions.
- Maps predicted emotions to Quranic verses using a dataset.
-
train_bert.py
,train_roberta.py
,train_distilbert.py
- Fine tune the pretrain models to the specific dataset
-
test_singlemodel.py
,test_ensemblemodel.py
- Testing the fine-tuned model
-
quran_emotions.csv
:- A dataset containing Quranic verses mapped to specific emotions.
-
model/
:- Contains the fine-tuned BERT and RoBERTa models and their tokenizers.
The backend API is built using Flask and provides an endpoint for emotion prediction.
POST /predict
The API expects a JSON payload with the following structure:
{
"text": "User's input text"
}
The API returns a JSON response with the following structure:
{
"predicted_emotion": "Emotion name",
"probabilities": [0.1, 0.2, 0.5, 0.2],
"quranic_verse": "Relevant Quranic verse (Surah X, Verse Y)"
}
- The input text is processed by both the fine-tuned BERT and RoBERTa models.
- The predictions from both models are combined using an ensemble method.
- The predicted emotion is mapped to a relevant Quranic verse using the
quran_emotions.csv
dataset.
- Python 3.8 or later
- Flask
- PyTorch
- Transformers library
- pandas
-
Clone the repository:
git clone https://github.com/your-username/QuranicJar.git cd QuranicJar
-
Install the required Python packages:
pip install -r requirements.txt
-
Ensure the
quran_emotions.csv
dataset is in thedataset/
directory. -
Run the Flask app:
python app.py
The backend will be available at
http://0.0.0.0:3000
.
- Open the swift directory in Xcode.
- Run the app on a simulator or a physical device.
- Ensure the backend API is running and accessible from the device.
- Python 3.8 or later
- Flask
- PyTorch
- Transformers
- pandas
- iOS 14.0 or later
- Xcode 12.0 or later
- Swift 5.0 or later
- Add support for more emotions and Quranic verses.
- Improve the emotion prediction model with additional training data.
- Enhance the UI/UX of the iOS app.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License. See the LICENSE file for details.
Developed by Fakhrul Fauzi