Spaces:
Sleeping
Sleeping
add readme
Browse files
README.md
CHANGED
|
@@ -27,10 +27,11 @@ A **RAG-powered chatbot** that provides HR knowledge and policy guidance for non
|
|
| 27 |
- [Qdrant](#qdrant)
|
| 28 |
- [Firecrawl](#firecrawl)
|
| 29 |
- [LangSmith](#langsmith)
|
|
|
|
| 30 |
- [Running the Application](#running-the-application)
|
| 31 |
- [Admin Interface](#admin-interface)
|
| 32 |
- [How It Works](#how-it-works)
|
| 33 |
-
- [Embedding the Chatbot](#embedding-the-chatbot)
|
| 34 |
- [Testing](#testing)
|
| 35 |
- [Troubleshooting](#troubleshooting)
|
| 36 |
|
|
@@ -310,23 +311,73 @@ FIRECRAWL_API_KEY="fc-your-firecrawl-api-key"
|
|
| 310 |
|
| 311 |
---
|
| 312 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 313 |
## Running the Application
|
| 314 |
|
| 315 |
-
### User Chat Interface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
|
| 317 |
```bash
|
| 318 |
python app.py
|
| 319 |
```
|
| 320 |
|
| 321 |
-
|
|
|
|
|
|
|
| 322 |
|
| 323 |
-
|
| 324 |
|
| 325 |
```bash
|
| 326 |
python admin.py
|
| 327 |
```
|
| 328 |
|
| 329 |
-
|
|
|
|
|
|
|
| 330 |
|
| 331 |
---
|
| 332 |
|
|
@@ -403,15 +454,123 @@ A regex-based check warns users when their query appears to contain names (e.g.,
|
|
| 403 |
|
| 404 |
---
|
| 405 |
|
| 406 |
-
## Embedding the Chatbot
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 407 |
|
| 408 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 409 |
|
| 410 |
```html
|
| 411 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 412 |
```
|
| 413 |
|
| 414 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 415 |
|
| 416 |
---
|
| 417 |
|
|
@@ -447,12 +606,52 @@ This tests connectivity to:
|
|
| 447 |
|
| 448 |
---
|
| 449 |
|
| 450 |
-
##
|
| 451 |
|
| 452 |
-
|
| 453 |
|
| 454 |
-
|
|
|
|
|
|
|
| 455 |
2. Select **Gradio** as the SDK
|
| 456 |
-
3. Push your code to the Space repository
|
| 457 |
-
4. Add all required environment variables as **Secrets** in the Space settings
|
| 458 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
- [Qdrant](#qdrant)
|
| 28 |
- [Firecrawl](#firecrawl)
|
| 29 |
- [LangSmith](#langsmith)
|
| 30 |
+
- [Deployment Model](#deployment-model)
|
| 31 |
- [Running the Application](#running-the-application)
|
| 32 |
- [Admin Interface](#admin-interface)
|
| 33 |
- [How It Works](#how-it-works)
|
| 34 |
+
- [Embedding the Chatbot Widget](#embedding-the-chatbot-widget)
|
| 35 |
- [Testing](#testing)
|
| 36 |
- [Troubleshooting](#troubleshooting)
|
| 37 |
|
|
|
|
| 311 |
|
| 312 |
---
|
| 313 |
|
| 314 |
+
## Deployment Model
|
| 315 |
+
|
| 316 |
+
This project uses a **split deployment** architecture: the user-facing chatbot runs in the cloud, while the admin dashboard runs on your local machine.
|
| 317 |
+
|
| 318 |
+
```
|
| 319 |
+
┌─────────────────────────────────┐ ┌─────────────────────────────┐
|
| 320 |
+
│ Hugging Face Spaces (Cloud) │ │ Your Local Machine │
|
| 321 |
+
│ │ │ │
|
| 322 |
+
│ app.py (port 7860) │ │ admin.py (port 7861) │
|
| 323 |
+
│ - User chat interface │ │ - Upload documents │
|
| 324 |
+
│ - RAG Q&A │ │ - Scrape web pages │
|
| 325 |
+
│ - Public access │ │ - Delete documents │
|
| 326 |
+
│ │ │ - View knowledge base │
|
| 327 |
+
└────────────┬────────────────────┘ └──────────┬──────────────────┘
|
| 328 |
+
│ │
|
| 329 |
+
└──────────┬───────────────────────────┘
|
| 330 |
+
│ Both connect to the same
|
| 331 |
+
▼ cloud services
|
| 332 |
+
┌─────────────────┐ ┌──────────────┐
|
| 333 |
+
│ Qdrant Cloud │ │ OpenAI API │
|
| 334 |
+
└─────────────────┘ └──────────────┘
|
| 335 |
+
```
|
| 336 |
+
|
| 337 |
+
| Component | Where it runs | Purpose | Access |
|
| 338 |
+
| ---------- | ----------------------- | ------------------------- | ---------------------------- |
|
| 339 |
+
| `app.py` | **Hugging Face Spaces** | User-facing chatbot | Public (anyone with the URL) |
|
| 340 |
+
| `admin.py` | **Your local machine** | Knowledge base management | Private (admin only) |
|
| 341 |
+
|
| 342 |
+
**Why this split?**
|
| 343 |
+
|
| 344 |
+
- The **chatbot** (`app.py`) is deployed to Hugging Face Spaces so end users can access it 24/7 via a public URL without needing any local setup.
|
| 345 |
+
- The **admin dashboard** (`admin.py`) runs locally because it performs sensitive operations (uploading documents, deleting data, scraping URLs). Keeping it local ensures only authorized administrators can modify the knowledge base.
|
| 346 |
+
- Both components share the same `.env` configuration and connect to the same Qdrant and OpenAI instances, so changes made via the admin dashboard are immediately reflected in the chatbot.
|
| 347 |
+
|
| 348 |
+
---
|
| 349 |
+
|
| 350 |
## Running the Application
|
| 351 |
|
| 352 |
+
### User Chat Interface (Cloud)
|
| 353 |
+
|
| 354 |
+
The chatbot is deployed on Hugging Face Spaces and accessible at:
|
| 355 |
+
|
| 356 |
+
```
|
| 357 |
+
https://pikamomo-hr-intervals-chatbot.hf.space
|
| 358 |
+
```
|
| 359 |
+
|
| 360 |
+
To deploy your own instance, see [Deploying to Hugging Face Spaces](#deploying-to-hugging-face-spaces) below.
|
| 361 |
+
|
| 362 |
+
For local development and testing, you can also run it locally:
|
| 363 |
|
| 364 |
```bash
|
| 365 |
python app.py
|
| 366 |
```
|
| 367 |
|
| 368 |
+
This opens the chatbot at **http://localhost:7860**.
|
| 369 |
+
|
| 370 |
+
### Admin Dashboard (Local)
|
| 371 |
|
| 372 |
+
The admin panel runs on your local machine. Start it with:
|
| 373 |
|
| 374 |
```bash
|
| 375 |
python admin.py
|
| 376 |
```
|
| 377 |
|
| 378 |
+
This opens the admin dashboard at **http://localhost:7861**. See [Admin Interface](#admin-interface) for details on each tab.
|
| 379 |
+
|
| 380 |
+
> **Important:** The admin dashboard is intentionally **not deployed** to the cloud. Always run it locally to maintain control over who can modify the knowledge base.
|
| 381 |
|
| 382 |
---
|
| 383 |
|
|
|
|
| 454 |
|
| 455 |
---
|
| 456 |
|
| 457 |
+
## Embedding the Chatbot Widget
|
| 458 |
+
|
| 459 |
+
The file `chatbot-widget.html` provides a ready-to-use **floating chat widget** that you can embed on any website. It renders a circular button in the bottom-right corner that opens the chatbot in a popup window — no page navigation required.
|
| 460 |
+
|
| 461 |
+
### Quick Start
|
| 462 |
+
|
| 463 |
+
The simplest way to add the chatbot to an existing web page is to copy three pieces from `chatbot-widget.html` into your site:
|
| 464 |
+
|
| 465 |
+
1. **CSS** (add to your `<head>` or stylesheet)
|
| 466 |
+
2. **HTML** (add before `</body>`)
|
| 467 |
+
3. **JavaScript** (add before `</body>`)
|
| 468 |
+
|
| 469 |
+
### Step 1 — Add the CSS
|
| 470 |
+
|
| 471 |
+
Copy the widget styles into your page's `<head>` (or into your existing CSS file). These styles are marked between `CHATBOT WIDGET STYLES - COPY FROM HERE` and `END OF CHATBOT WIDGET STYLES` in the source file.
|
| 472 |
+
|
| 473 |
+
### Step 2 — Add the HTML
|
| 474 |
+
|
| 475 |
+
Add the following HTML just before your closing `</body>` tag. Update the `src` URL to point to your own Hugging Face Space:
|
| 476 |
|
| 477 |
+
```html
|
| 478 |
+
<!-- Chat Toggle Button -->
|
| 479 |
+
<button class="chat-widget-button" id="chatWidgetButton" onclick="toggleChat()">
|
| 480 |
+
<span class="chat-widget-badge">1</span>
|
| 481 |
+
<svg viewBox="0 0 24 24" id="chatIcon">
|
| 482 |
+
<path
|
| 483 |
+
d="M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H6l-2 2V4h16v12z"
|
| 484 |
+
/>
|
| 485 |
+
</svg>
|
| 486 |
+
<svg viewBox="0 0 24 24" id="closeIcon" style="display: none;">
|
| 487 |
+
<path
|
| 488 |
+
d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"
|
| 489 |
+
/>
|
| 490 |
+
</svg>
|
| 491 |
+
</button>
|
| 492 |
+
|
| 493 |
+
<!-- Chat Window -->
|
| 494 |
+
<div class="chat-widget-window" id="chatWidgetWindow">
|
| 495 |
+
<div class="chat-widget-header">
|
| 496 |
+
<div class="chat-widget-header-info">
|
| 497 |
+
<div class="chat-widget-avatar">🤖</div>
|
| 498 |
+
<div class="chat-widget-title">
|
| 499 |
+
<h3>HR Assistant</h3>
|
| 500 |
+
<span><span class="status-dot"></span> Online</span>
|
| 501 |
+
</div>
|
| 502 |
+
</div>
|
| 503 |
+
<button class="chat-widget-close" onclick="toggleChat()">
|
| 504 |
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">
|
| 505 |
+
<path
|
| 506 |
+
d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"
|
| 507 |
+
/>
|
| 508 |
+
</svg>
|
| 509 |
+
</button>
|
| 510 |
+
</div>
|
| 511 |
+
<div class="chat-widget-body">
|
| 512 |
+
<!-- 👇 Change this URL to your Hugging Face Space URL -->
|
| 513 |
+
<iframe
|
| 514 |
+
src="https://pikamomo-hr-intervals-chatbot.hf.space"
|
| 515 |
+
title="HR Chatbot"
|
| 516 |
+
loading="lazy"
|
| 517 |
+
>
|
| 518 |
+
</iframe>
|
| 519 |
+
</div>
|
| 520 |
+
</div>
|
| 521 |
+
```
|
| 522 |
+
|
| 523 |
+
### Step 3 — Add the JavaScript
|
| 524 |
+
|
| 525 |
+
Add this script after the HTML above:
|
| 526 |
|
| 527 |
```html
|
| 528 |
+
<script>
|
| 529 |
+
let isOpen = false;
|
| 530 |
+
const button = document.getElementById("chatWidgetButton");
|
| 531 |
+
const window_el = document.getElementById("chatWidgetWindow");
|
| 532 |
+
const chatIcon = document.getElementById("chatIcon");
|
| 533 |
+
const closeIcon = document.getElementById("closeIcon");
|
| 534 |
+
const badge = document.querySelector(".chat-widget-badge");
|
| 535 |
+
|
| 536 |
+
function toggleChat() {
|
| 537 |
+
isOpen = !isOpen;
|
| 538 |
+
if (isOpen) {
|
| 539 |
+
window_el.classList.add("open");
|
| 540 |
+
button.classList.add("active");
|
| 541 |
+
chatIcon.style.display = "none";
|
| 542 |
+
closeIcon.style.display = "block";
|
| 543 |
+
badge.style.display = "none";
|
| 544 |
+
} else {
|
| 545 |
+
window_el.classList.remove("open");
|
| 546 |
+
button.classList.remove("active");
|
| 547 |
+
chatIcon.style.display = "block";
|
| 548 |
+
closeIcon.style.display = "none";
|
| 549 |
+
}
|
| 550 |
+
}
|
| 551 |
+
|
| 552 |
+
// Close on Escape key
|
| 553 |
+
document.addEventListener("keydown", function (e) {
|
| 554 |
+
if (e.key === "Escape" && isOpen) {
|
| 555 |
+
toggleChat();
|
| 556 |
+
}
|
| 557 |
+
});
|
| 558 |
+
</script>
|
| 559 |
```
|
| 560 |
|
| 561 |
+
### Customization
|
| 562 |
+
|
| 563 |
+
| What to change | Where | Details |
|
| 564 |
+
| --------------- | -------------------------------------- | ---------------------------------------------------------------------- |
|
| 565 |
+
| Chatbot URL | `<iframe src="...">` | Replace with your Hugging Face Space URL |
|
| 566 |
+
| Widget colors | CSS `background: linear-gradient(...)` | Change the gradient on `.chat-widget-button` and `.chat-widget-header` |
|
| 567 |
+
| Widget size | CSS `.chat-widget-window` | Adjust `width` (400px) and `height` (600px) |
|
| 568 |
+
| Button position | CSS `.chat-widget-button` | Change `bottom` and `right` values |
|
| 569 |
+
| Header title | HTML `<h3>HR Assistant</h3>` | Replace with your preferred name |
|
| 570 |
+
|
| 571 |
+
### Full Working Example
|
| 572 |
+
|
| 573 |
+
Open `chatbot-widget.html` directly in a browser to see the widget in action on a demo page. The file is self-contained and requires no build step — just open it and click the chat button in the bottom-right corner.
|
| 574 |
|
| 575 |
---
|
| 576 |
|
|
|
|
| 606 |
|
| 607 |
---
|
| 608 |
|
| 609 |
+
## Deploying to Hugging Face Spaces
|
| 610 |
|
| 611 |
+
The user-facing chatbot (`app.py`) is designed to run on **Hugging Face Spaces**. The admin dashboard (`admin.py`) stays on your local machine.
|
| 612 |
|
| 613 |
+
### Setting Up the Space
|
| 614 |
+
|
| 615 |
+
1. Create a new Space at [huggingface.co/spaces](https://huggingface.co/spaces)
|
| 616 |
2. Select **Gradio** as the SDK
|
| 617 |
+
3. Push your code to the Space repository (or link it to your Git repo)
|
| 618 |
+
4. Add all required environment variables as **Secrets** in the Space settings:
|
| 619 |
+
|
| 620 |
+
| Secret | Value |
|
| 621 |
+
| ------------------- | ----------------------------------------------------- |
|
| 622 |
+
| `OPENAI_API_KEY` | Your OpenAI API key |
|
| 623 |
+
| `QDRANT_URL` | Your Qdrant cluster URL |
|
| 624 |
+
| `QDRANT_API_KEY` | Your Qdrant API key |
|
| 625 |
+
| `QDRANT_COLLECTION` | `hr-intervals` (or your collection name) |
|
| 626 |
+
| `LANGSMITH_TRACING` | `false` (or `true` if you want tracing in production) |
|
| 627 |
+
| `LANGSMITH_API_KEY` | Your LangSmith API key (if tracing is enabled) |
|
| 628 |
+
| `LANGSMITH_PROJECT` | `hr-intervals-chatbot` |
|
| 629 |
+
|
| 630 |
+
5. The Space will automatically install dependencies from `requirements.txt` and start `app.py`
|
| 631 |
+
6. Once deployed, your chatbot will be available at: `https://<your-username>-<space-name>.hf.space`
|
| 632 |
+
|
| 633 |
+
### Managing the Knowledge Base
|
| 634 |
+
|
| 635 |
+
After the Space is live, manage the knowledge base from your local machine:
|
| 636 |
+
|
| 637 |
+
```bash
|
| 638 |
+
# 1. Make sure your local .env has the SAME Qdrant credentials as the Space
|
| 639 |
+
# 2. Start the admin dashboard
|
| 640 |
+
python admin.py
|
| 641 |
+
```
|
| 642 |
+
|
| 643 |
+
Any documents you upload, scrape, or delete through the local admin dashboard will immediately be available to the cloud-hosted chatbot — because both connect to the same Qdrant instance.
|
| 644 |
+
|
| 645 |
+
### Embedding on Your Website
|
| 646 |
+
|
| 647 |
+
Once your Space is running, you can embed the chatbot on any website using the widget (see [Embedding the Chatbot Widget](#embedding-the-chatbot-widget)). Simply set the iframe `src` to your Space URL:
|
| 648 |
+
|
| 649 |
+
```html
|
| 650 |
+
<iframe src="https://pikamomo-hr-intervals-chatbot.hf.space" ...></iframe>
|
| 651 |
+
```
|
| 652 |
+
|
| 653 |
+
---
|
| 654 |
+
|
| 655 |
+
## License
|
| 656 |
+
|
| 657 |
+
This project is developed for non-profit HR use. See your organization's licensing terms for details.
|