--- title: Reem โ€” Virtual AI Interview Agent emoji: ๐Ÿ“ž colorFrom: green colorTo: yellow sdk: docker pinned: false license: mit --- # ๐Ÿ“ž Reem โ€” Real-Time Streaming Voice RAG Bot **XYZ Holdings Virtual Call Centre** โ€” powered by Deepgram STT ยท Groq LLM ยท edge-tts --- ## Architecture ``` Browser mic โ†’ Gradio Audio โ†’ Deepgram STT (nova-2, multilingual) โ†“ Router (sql / rag) โ†™ โ†˜ SQLite orders FAISS + SentenceTransformer โ†˜ โ†™ Groq LLaMA-3.3-70b (streaming) โ†“ edge-tts TTS โ†“ Gradio Audio (autoplay) ``` --- ## Features | Feature | Details | |---|---| | **STT** | Deepgram nova-2, auto language detection (EN / AR / UR) | | **LLM** | Groq `llama-3.3-70b-versatile` with streaming | | **TTS** | edge-tts โ€” `en-US-AriaNeural`, `ar-SA-ZariyahNeural`, `ur-PK-UzmaNeural` | | **Memory** | 10-turn sliding window + entity cache (order IDs, customer name) | | **Routing** | SQL path for order tracking, RAG path for knowledge base Q&A | | **Languages** | English ยท Arabic ยท Urdu | --- ## Environment Variables Set these in **HF Spaces โ†’ Settings โ†’ Repository secrets**: | Variable | Required | Description | |---|---|---| | `GROQ_API_KEY` | โœ… | [console.groq.com](https://console.groq.com) | | `DEEPGRAM_API_KEY` | โœ… | [console.deepgram.com](https://console.deepgram.com) | | `LIVEKIT_API_KEY` | โฌœ | Reserved for future WebRTC streaming | --- ## Deployment โ€” HF Spaces (Gradio SDK) 1. Create a new Space โ†’ **Gradio** SDK 2. Push these files โ€” no Dockerfile needed: ``` app.py requirements.txt README.md ``` 3. Add secrets under **Settings โ†’ Repository secrets**: `GROQ_API_KEY`, `DEEPGRAM_API_KEY` 4. HF installs `requirements.txt` automatically and runs `app.py` --- ## Knowledge Base Setup 1. Open **Admin Panel** (left sidebar) after launch 2. Upload one or more `.txt` files โ†’ click **Build KB** 3. FAISS index is built in-memory and persisted to `faiss.index` + `chunks.npy` ## Orders Database Setup 1. Export your SQLite `.db` file with an `orders` table: ```sql CREATE TABLE orders ( order_id INTEGER PRIMARY KEY, order_date TEXT, customer_name TEXT, customer_city TEXT, customer_address TEXT, status TEXT, delivery_date TEXT, comments TEXT ); ``` 2. Upload via **Admin Panel โ†’ Orders Database** --- ## Usage Flow 1. Page loads โ†’ **welcome message plays** in EN / AR / UR 2. Say or click your **language** โ†’ Reem confirms 3. **Speak** into mic or **type** in the text box 4. Reem routes your query: - Order number / tracking keywords โ†’ **SQL lookup** - General questions โ†’ **RAG knowledge base** 5. Response **streams** from Groq โ†’ TTS plays automatically 6. Reem **remembers** order IDs and customer name across turns --- ## Local Development ```bash # Create venv python -m venv .venv && source .venv/bin/activate # Install pip install -r requirements.txt # Set env vars export GROQ_API_KEY=gsk_... export DEEPGRAM_API_KEY=... # Run python app.py # โ†’ http://localhost:7860 ``` --- ## File Structure ``` โ”œโ”€โ”€ app.py # Main Gradio app โ”œโ”€โ”€ requirements.txt โ”œโ”€โ”€ README.md # HF Spaces config frontmatter lives here โ”œโ”€โ”€ faiss.index # Auto-generated after KB build โ”œโ”€โ”€ chunks.npy # Auto-generated after KB build โ”œโ”€โ”€ saudi_orders_database.db # Upload via Admin Panel โ””โ”€โ”€ agent_photo.jpg # Optional โ€” replaces emoji avatar ``` --- ## Differences from Streamlit Version | Aspect | Streamlit + Railway | Gradio on HF Spaces | |---|---|---| | Port management | FastAPI proxy required | Single port, native | | Streaming TTS | `st.components.v1.html` workaround | `gr.Audio(autoplay=True)` | | STT | `streamlit-mic-recorder` | `gr.Audio(sources=["microphone"])` | | Re-render issues | Duplicate responses on rerun | State-based, no reruns | | Barge-in | Manual WebSocket lifecycle | Deepgram `stop_recording` event |