MoodMate is a chatbot designed as a personal learning project to explore and practice skills in modern technologies like LangChain, FastAPI, and Streamlit. While it provides empathetic responses and basic emotional support, its primary goal is to demonstrate the integration of these tools in a functional, interactive application.
MoodMate demonstrates the integration of modern tools and frameworks to create a functional chatbot application:
- Implements
ConversationSummaryMemory
to provide context-aware interactions. - Utilizes
ConversationChain
and Google’s LLM (ChatGoogleGenerativeAI) to power the chatbot's conversational logic.
- Designed an API endpoint (
/chat
) to handle user inputs and return chatbot responses.
- Developed an interactive web interface to send user queries to the API and display responses.
- Containerized the entire system, ensuring portability and ease of deployment.
- Deployed the application online, making it accessible from anywhere.
The moodmate/
project directory is organized as follows:
moodmate/
├── api/ # Backend code for the chatbot API
│ ├── .env # Include your GOOGLE_API_KEY
│ ├── api.py # API server entry point, handles requests and responses
│ ├── chatbot.py # Core chatbot logic, including conversation management
│ ├── requirements.txt # Dependencies required for the backend
│ └── Dockerfile # Dockerfile for containerizing the backend
│
├── app/ # Frontend application code
│ ├── app.py # Streamlit app entry point, provides user interface
│ ├── requirements.txt # Dependencies required for the frontend
│ └── Dockerfile # Dockerfile for containerizing the frontend
│
├── images/ # Project assets like screenshots
│ └── moodmate.png # Screenshot of the MoodMate interface
│
├── .dockerignore # Specifies files to exclude from Docker builds
├── .gitignore # Specifies files to exclude from Git commits
├── docker-compose.yml # Configuration for Docker Compose to run the project
└── README.md # Project documentation
To run MoodMate locally, follow these steps:
git clone https://github.com/AhmedShetaia/moodmate.git
cd moodmate
python -m venv myenv
make sure to activate it
myenv\Scripts\activate
MoodMate requires a Google API Key to access Google’s LLM for powering chatbot interactions. Follow these steps to set it up:
- Visit the Google Cloud Console.
- Create a new project or select an existing one.
- Enable the Generative AI API or the relevant service.
- Generate an API key from the APIs & Services section.
touch api/.env
GOOGLE_API_KEY=your-google-api-key
Replace your-google-api-key
with the actual API key obtained from Google Cloud.
Additional environment variables required for the system are specified in the Dockerfile and managed during containerization.
pip install docker
docker-compose up --build
Open the Streamlit server using the link provided in the terminal output.
MoodMate is deployed using Google Cloud Run, enabling easy scalability and online accessibility. Follow these steps for deployment:
- Create a Google Cloud account.
- Ensure billing is enabled for your account.
- Create a new project in Google Cloud (e.g.,
moodmate-project
). - Enable the following services:
- Cloud Run
- Artifact Registry
- Container Registry
- Grant necessary IAM permissions for deployment (e.g., Cloud Run Admin, Storage Admin).
- Navigate to the Artifact Registry in the Google Cloud Console.
- Create a new Docker repository:
- Repository name:
moodmate-repo
- Location: Choose a region close to your user base.
- Format: Docker.
- Repository name:
- Authenticate Docker with Google Cloud:
To authenticate Docker with Google Cloud, follow these steps:
Run the following command to generate and print your access token:
gcloud auth print-access-token
Copy the token from the output.
Run the docker login command and paste the token when prompted for a password:
For Artifact Registry:
docker login -u oauth2accesstoken https://<region>-docker.pkg.dev
Replace <region>
with your registry's region (e.g., us, me-central1, or asia).
When prompted for a password after running the docker login command, paste the token you copied in Step 1.
Output should look like this :
$ docker login -u oauth2accesstoken https://gcr.io
Password:
Login Succeeded
Now, you are authenticated with Docker using the manually copied token.
docker build -t REGION-docker.pkg.dev/PROJECT_ID/moodmate-repo/api-backend ./api
docker build -t REGION-docker.pkg.dev/PROJECT_ID/moodmate-repo/app-frontend ./app
docker push REGION-docker.pkg.dev/PROJECT_ID/moodmate-repo/api-backend
docker push REGION-docker.pkg.dev/PROJECT_ID/moodmate-repo/app-frontend
gcloud run deploy moodmate-api \
--image REGION-docker.pkg.dev/PROJECT_ID/moodmate-repo/api-backend \
--platform managed \
--region REGION \
--allow-unauthenticated
gcloud run deploy moodmate-app \
--image REGION-docker.pkg.dev/PROJECT_ID/moodmate-repo/app-frontend \
--platform managed \
--region REGION \
--allow-unauthenticated \
--set-env-vars API_URL=https://moodmate-api-YOUR_PROJECT_ID.REGION.run.app/
This project is licensed under the MIT License. See the LICENSE file for details.
Feel free to connect with me on LinkedIn. I’d love to hear your feedback, discuss the project, or collaborate on future ideas!