Spaces:
Running
Running
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,15 +1,156 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 6.5.1
|
| 8 |
-
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
-
|
| 11 |
-
hf_oauth_scopes:
|
| 12 |
-
- inference-api
|
| 13 |
---
|
| 14 |
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Reem — Virtual Call Centre Voice Bot
|
| 3 |
+
emoji: 📞
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: yellow
|
| 6 |
sdk: gradio
|
|
|
|
|
|
|
| 7 |
pinned: false
|
| 8 |
+
license: mit
|
|
|
|
|
|
|
| 9 |
---
|
| 10 |
|
| 11 |
+
# 📞 Reem — Real-Time Streaming Voice RAG Bot
|
| 12 |
+
|
| 13 |
+
**XYZ Holdings Virtual Call Centre** — powered by Deepgram STT · Groq LLM · edge-tts
|
| 14 |
+
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
## Architecture
|
| 18 |
+
|
| 19 |
+
```
|
| 20 |
+
Browser mic → Gradio Audio → Deepgram STT (nova-2, multilingual)
|
| 21 |
+
↓
|
| 22 |
+
Router (sql / rag)
|
| 23 |
+
↙ ↘
|
| 24 |
+
SQLite orders FAISS + SentenceTransformer
|
| 25 |
+
↘ ↙
|
| 26 |
+
Groq LLaMA-3.3-70b (streaming)
|
| 27 |
+
↓
|
| 28 |
+
edge-tts TTS
|
| 29 |
+
↓
|
| 30 |
+
Gradio Audio (autoplay)
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
---
|
| 34 |
+
|
| 35 |
+
## Features
|
| 36 |
+
|
| 37 |
+
| Feature | Details |
|
| 38 |
+
|---|---|
|
| 39 |
+
| **STT** | Deepgram nova-2, auto language detection (EN / AR / UR) |
|
| 40 |
+
| **LLM** | Groq `llama-3.3-70b-versatile` with streaming |
|
| 41 |
+
| **TTS** | edge-tts — `en-US-AriaNeural`, `ar-SA-ZariyahNeural`, `ur-PK-UzmaNeural` |
|
| 42 |
+
| **Memory** | 10-turn sliding window + entity cache (order IDs, customer name) |
|
| 43 |
+
| **Routing** | SQL path for order tracking, RAG path for knowledge base Q&A |
|
| 44 |
+
| **Languages** | English · Arabic · Urdu |
|
| 45 |
+
|
| 46 |
+
---
|
| 47 |
+
|
| 48 |
+
## Environment Variables
|
| 49 |
+
|
| 50 |
+
Set these in **HF Spaces → Settings → Repository secrets**:
|
| 51 |
+
|
| 52 |
+
| Variable | Required | Description |
|
| 53 |
+
|---|---|---|
|
| 54 |
+
| `GROQ_API_KEY` | ✅ | [console.groq.com](https://console.groq.com) |
|
| 55 |
+
| `DEEPGRAM_API_KEY` | ✅ | [console.deepgram.com](https://console.deepgram.com) |
|
| 56 |
+
| `LIVEKIT_API_KEY` | ⬜ | Reserved for future WebRTC streaming |
|
| 57 |
+
|
| 58 |
+
---
|
| 59 |
+
|
| 60 |
+
## Deployment — HF Spaces (Docker SDK)
|
| 61 |
+
|
| 62 |
+
1. Create a new Space → **Docker** SDK
|
| 63 |
+
2. Push all files:
|
| 64 |
+
```
|
| 65 |
+
app.py
|
| 66 |
+
requirements.txt
|
| 67 |
+
Dockerfile
|
| 68 |
+
README.md
|
| 69 |
+
```
|
| 70 |
+
3. Add secrets (`GROQ_API_KEY`, `DEEPGRAM_API_KEY`)
|
| 71 |
+
4. Space auto-builds and launches on port **7860**
|
| 72 |
+
|
| 73 |
+
---
|
| 74 |
+
|
| 75 |
+
## Knowledge Base Setup
|
| 76 |
+
|
| 77 |
+
1. Open **Admin Panel** (left sidebar) after launch
|
| 78 |
+
2. Upload one or more `.txt` files → click **Build KB**
|
| 79 |
+
3. FAISS index is built in-memory and persisted to `faiss.index` + `chunks.npy`
|
| 80 |
+
|
| 81 |
+
## Orders Database Setup
|
| 82 |
+
|
| 83 |
+
1. Export your SQLite `.db` file with an `orders` table:
|
| 84 |
+
```sql
|
| 85 |
+
CREATE TABLE orders (
|
| 86 |
+
order_id INTEGER PRIMARY KEY,
|
| 87 |
+
order_date TEXT,
|
| 88 |
+
customer_name TEXT,
|
| 89 |
+
customer_city TEXT,
|
| 90 |
+
customer_address TEXT,
|
| 91 |
+
status TEXT,
|
| 92 |
+
delivery_date TEXT,
|
| 93 |
+
comments TEXT
|
| 94 |
+
);
|
| 95 |
+
```
|
| 96 |
+
2. Upload via **Admin Panel → Orders Database**
|
| 97 |
+
|
| 98 |
+
---
|
| 99 |
+
|
| 100 |
+
## Usage Flow
|
| 101 |
+
|
| 102 |
+
1. Page loads → **welcome message plays** in EN / AR / UR
|
| 103 |
+
2. Say or click your **language** → Reem confirms
|
| 104 |
+
3. **Speak** into mic or **type** in the text box
|
| 105 |
+
4. Reem routes your query:
|
| 106 |
+
- Order number / tracking keywords → **SQL lookup**
|
| 107 |
+
- General questions → **RAG knowledge base**
|
| 108 |
+
5. Response **streams** from Groq → TTS plays automatically
|
| 109 |
+
6. Reem **remembers** order IDs and customer name across turns
|
| 110 |
+
|
| 111 |
+
---
|
| 112 |
+
|
| 113 |
+
## Local Development
|
| 114 |
+
|
| 115 |
+
```bash
|
| 116 |
+
# Create venv
|
| 117 |
+
python -m venv .venv && source .venv/bin/activate
|
| 118 |
+
|
| 119 |
+
# Install
|
| 120 |
+
pip install -r requirements.txt
|
| 121 |
+
|
| 122 |
+
# Set env vars
|
| 123 |
+
export GROQ_API_KEY=gsk_...
|
| 124 |
+
export DEEPGRAM_API_KEY=...
|
| 125 |
+
|
| 126 |
+
# Run
|
| 127 |
+
python app.py
|
| 128 |
+
# → http://localhost:7860
|
| 129 |
+
```
|
| 130 |
+
|
| 131 |
+
---
|
| 132 |
+
|
| 133 |
+
## File Structure
|
| 134 |
+
|
| 135 |
+
```
|
| 136 |
+
├── app.py # Main Gradio app
|
| 137 |
+
├── requirements.txt
|
| 138 |
+
├── Dockerfile
|
| 139 |
+
├── README.md
|
| 140 |
+
├── faiss.index # Auto-generated after KB build
|
| 141 |
+
├── chunks.npy # Auto-generated after KB build
|
| 142 |
+
├── saudi_orders_database.db # Upload via Admin Panel
|
| 143 |
+
└── agent_photo.jpg # Optional — replaces emoji avatar
|
| 144 |
+
```
|
| 145 |
+
|
| 146 |
+
---
|
| 147 |
+
|
| 148 |
+
## Differences from Streamlit Version
|
| 149 |
+
|
| 150 |
+
| Aspect | Streamlit + Railway | Gradio on HF Spaces |
|
| 151 |
+
|---|---|---|
|
| 152 |
+
| Port management | FastAPI proxy required | Single port, native |
|
| 153 |
+
| Streaming TTS | `st.components.v1.html` workaround | `gr.Audio(autoplay=True)` |
|
| 154 |
+
| STT | `streamlit-mic-recorder` | `gr.Audio(sources=["microphone"])` |
|
| 155 |
+
| Re-render issues | Duplicate responses on rerun | State-based, no reruns |
|
| 156 |
+
| Barge-in | Manual WebSocket lifecycle | Deepgram `stop_recording` event |
|