swawire/meridian-chatbot
Meridian Electronics — Customer Support Chatbot
Production-style prototype: a Gradio chat UI backed by OpenAI gpt-4o-mini and a remote MCP server (Streamable HTTP). All product, order, and authentication operations go through MCP tools — the app does not talk to a database directly.
Features
- Authentication — email + PIN via MCP (before orders or order history); Gradio session state tracks
is_authenticated/customer_emailafter successful verification. - Products — availability, search, and details via MCP tools.
- Orders — place orders and view history through MCP.
- Resilient behavior — OpenAI and MCP failures surface as short, user-friendly messages (no stack traces in the UI).
Step-by-step: Run the project locally
1. Clone the repository
Git (HTTPS):
git clone https://github.com/SilasAmisi/meridian-chatbot.git
cd meridian-chatbotIf you use SSH, replace the URL with your SSH remote. On Windows, the same commands work in PowerShell, Command Prompt, or Git Bash.
2. Install requirements
Create and activate a virtual environment (recommended), then install dependencies:
Windows (PowerShell):
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txtmacOS / Linux:
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtUse Python 3.10+.
3. Add .env locally
Copy the example env file and fill in your OpenAI key:
Windows:
copy .env.example .envmacOS / Linux:
cp .env.example .envEdit .env in your editor and set:
OPENAI_API_KEY=sk-...your-real-key...Do not commit .env — it is listed in .gitignore.
4. Run locally with python app.py
From the meridian-chatbot directory (with the virtual environment activated):
python app.pyOpen the URL Gradio prints (typically http://127.0.0.1:7860). The app listens on 0.0.0.0 and port 7860 (or the PORT environment variable), which matches Hugging Face Spaces.
Step-by-step: Hugging Face Space
5. Create a Hugging Face Space
- Sign in at huggingface.co.
- Click your avatar → New Space (or go to huggingface.co/new-space).
- Choose a Space name (for example
meridian-chatbot) and owner (User or Organization). - Set SDK to Gradio (this project uses
app.pyas the entry file). - Choose visibility (Public or Private) and hardware if needed, then Create Space.
You will get a Space URL like:
https://huggingface.co/spaces/<your-username>/<your-space-name>
Remember `<your-username>/<your-space-name>` — you need it for git remotes and for GitHub Actions (as HF_SPACE_REPO).
6. Add OPENAI_API_KEY as a Space secret
- Open your Space on Hugging Face.
- Go to Settings (tab on the Space page).
- Open Repository secrets (or Variables and secrets → secrets for the Space).
- Add a new secret:
- Name:
OPENAI_API_KEY - Value: your OpenAI API key (
sk-...).
Save. The Space injects this as an environment variable at runtime, which chatbot.py reads via os.environ (and python-dotenv is optional on Spaces).
7. Push to Hugging Face to trigger deployment
The Space runs from the Git repository hosted on Hugging Face. Any push to that repo’s default branch (`main`) starts a new build and deployment.
Option A — Push from your computer (first-time or manual deploy)
- Install the Hugging Face CLI (once):
pip install huggingface_hub - Log in:
hf auth login(paste a write token from Settings → Access Tokens), or non-interactive:hf auth login --token YOUR_TOKEN --add-to-git-credential. - In your local
meridian-chatbotclone, add the Space as a remote (replaceYOUR_USERandYOUR_SPACE):
git remote add huggingface https://huggingface.co/spaces/YOUR_USER/YOUR_SPACE.git- Push your
mainbranch:
git push huggingface mainIf the Space already had an initial commit from the web UI, you may need `git push --force huggingface main` once to replace it with this repo — only do that if you are sure you will not lose wanted changes on the Space.
Option B — Push to GitHub `main` to auto-deploy (recommended)
This repository includes `.github/workflows/deploy.yml`. On every push to `main`, GitHub Actions force-pushes to your Space over HTTPS using `HF_TOKEN` (credentials are URL-encoded for git; no huggingface-cli / hf in CI). The workflow uses `actions/checkout@v6` and opts into Node.js 24 for JavaScript-based actions to match current GitHub Actions defaults.
- In your GitHub repository: Settings → Secrets and variables → Actions → New repository secret.
- Add `HF_TOKEN`: a Hugging Face access token with write permission (role write is enough to push to Spaces you own).
- Add `HF_SPACE_REPO`: the Space id in the form `username/space-name` (example:
swawire/meridian-chatbot). Nohttps://, nospaces/prefix — onlyowner/repo-style-nameas shown in the Space URL path after/spaces/. - Push (or merge) to `main` on GitHub. Open the Actions tab to confirm the Deploy to Hugging Face Space workflow succeeded.
If either secret is missing, the workflow fails with an error pointing you back to this README.
Tests
From the meridian-chatbot directory, with dependencies installed:
python -m pytest tests/ -vtests/test_mcp_client.py hits the real MCP endpoint (needs network). tests/test_chatbot.py mocks OpenAI and does not call the live API.
Project layout
The default MCP URL is in mcp_client.py. Override with `MCP_SERVER_URL` in .env if needed. Tools are discovered at runtime — tool names are not hardcoded for discovery.
License
Use and modify for your Meridian Electronics prototype as needed.
