Spaces:
Running
Running
changed according to spaces
Browse files- README.md +20 -6
- __pycache__/app.cpython-314.pyc +0 -0
- app.py +20 -10
README.md
CHANGED
|
@@ -14,7 +14,7 @@ pinned: false
|
|
| 14 |
|
| 15 |
A Python demo chatbot that:
|
| 16 |
|
| 17 |
-
- loads
|
| 18 |
- scrapes the configured website
|
| 19 |
- builds embeddings using HuggingFace models
|
| 20 |
- retrieves relevant chunks (RAG)
|
|
@@ -28,11 +28,13 @@ A Python demo chatbot that:
|
|
| 28 |
pip install -r requirements.txt
|
| 29 |
```
|
| 30 |
|
| 31 |
-
2. Configure
|
| 32 |
-
- `
|
| 33 |
-
- `
|
| 34 |
-
- `
|
| 35 |
-
- `
|
|
|
|
|
|
|
| 36 |
|
| 37 |
## Run CLI Mode
|
| 38 |
|
|
@@ -49,3 +51,15 @@ python app.py
|
|
| 49 |
```
|
| 50 |
|
| 51 |
Interactive web interface with real-time answers and citations display.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
A Python demo chatbot that:
|
| 16 |
|
| 17 |
+
- loads configuration from environment variables or `config.yaml`
|
| 18 |
- scrapes the configured website
|
| 19 |
- builds embeddings using HuggingFace models
|
| 20 |
- retrieves relevant chunks (RAG)
|
|
|
|
| 28 |
pip install -r requirements.txt
|
| 29 |
```
|
| 30 |
|
| 31 |
+
2. Configure environment variables:
|
| 32 |
+
- `SAMBANOVA_API_KEY`: your SambaNova API key
|
| 33 |
+
- `WEBSITE`: the URL to scrape
|
| 34 |
+
- `EMBEDDING_MODEL`: HuggingFace model (default: `sentence-transformers/all-MiniLM-L6-v2`)
|
| 35 |
+
- `SYSTEM_PROMPT`: optional behavior prompt
|
| 36 |
+
|
| 37 |
+
Or create `config.yaml` with these keys.
|
| 38 |
|
| 39 |
## Run CLI Mode
|
| 40 |
|
|
|
|
| 51 |
```
|
| 52 |
|
| 53 |
Interactive web interface with real-time answers and citations display.
|
| 54 |
+
|
| 55 |
+
## Hugging Face Spaces
|
| 56 |
+
|
| 57 |
+
For deployment on Hugging Face Spaces:
|
| 58 |
+
|
| 59 |
+
1. Set the following secrets in your Space settings:
|
| 60 |
+
- `SAMBANOVA_API_KEY`
|
| 61 |
+
- `WEBSITE`
|
| 62 |
+
- `EMBEDDING_MODEL` (optional)
|
| 63 |
+
- `SYSTEM_PROMPT` (optional)
|
| 64 |
+
|
| 65 |
+
2. The app will automatically use these environment variables.
|
__pycache__/app.cpython-314.pyc
ADDED
|
Binary file (5.38 kB). View file
|
|
|
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from pathlib import Path
|
| 3 |
from sambanova import SambaNova
|
| 4 |
from langchain_huggingface import HuggingFaceEmbeddings
|
|
@@ -20,19 +21,28 @@ def init_resources():
|
|
| 20 |
if RESOURCE_STATE:
|
| 21 |
return RESOURCE_STATE
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
config
|
| 27 |
-
llm_api_key
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
if not llm_api_key or not website:
|
| 32 |
-
raise ValueError("
|
| 33 |
|
| 34 |
-
embed_model = HuggingFaceEmbeddings(model_name=
|
| 35 |
-
corpus = build_rag_corpus(
|
| 36 |
client = SambaNova(
|
| 37 |
api_key=llm_api_key,
|
| 38 |
base_url="https://api.sambanova.ai/v1",
|
|
@@ -40,7 +50,7 @@ def init_resources():
|
|
| 40 |
)
|
| 41 |
|
| 42 |
RESOURCE_STATE.update(
|
| 43 |
-
config=
|
| 44 |
website=website,
|
| 45 |
system_prompt=system_prompt,
|
| 46 |
embed_model=embed_model,
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
from pathlib import Path
|
| 4 |
from sambanova import SambaNova
|
| 5 |
from langchain_huggingface import HuggingFaceEmbeddings
|
|
|
|
| 21 |
if RESOURCE_STATE:
|
| 22 |
return RESOURCE_STATE
|
| 23 |
|
| 24 |
+
# Try to load from environment variables first (for Spaces)
|
| 25 |
+
llm_api_key = os.environ.get("SAMBANOVA_API_KEY")
|
| 26 |
+
website = os.environ.get("WEBSITE")
|
| 27 |
+
embedding_model_name = os.environ.get("EMBEDDING_MODEL", "sentence-transformers/all-MiniLM-L6-v2")
|
| 28 |
+
system_prompt = os.environ.get("SYSTEM_PROMPT", "You are a helpful assistant.")
|
| 29 |
|
| 30 |
+
# Fallback to config.yaml if env vars not set
|
| 31 |
+
if not llm_api_key or not website:
|
| 32 |
+
if CONFIG_PATH.exists():
|
| 33 |
+
config = load_config(CONFIG_PATH)
|
| 34 |
+
llm_api_key = llm_api_key or config.get("sambanova_api_key")
|
| 35 |
+
website = website or config.get("website")
|
| 36 |
+
embedding_model_name = embedding_model_name or config.get("embedding_model", "sentence-transformers/all-MiniLM-L6-v2")
|
| 37 |
+
system_prompt = system_prompt or config.get("system_prompt", "You are a helpful assistant.")
|
| 38 |
+
else:
|
| 39 |
+
raise ValueError("Please set SAMBANOVA_API_KEY and WEBSITE environment variables or provide config.yaml")
|
| 40 |
|
| 41 |
if not llm_api_key or not website:
|
| 42 |
+
raise ValueError("SAMBANOVA_API_KEY and WEBSITE are required")
|
| 43 |
|
| 44 |
+
embed_model = HuggingFaceEmbeddings(model_name=embedding_model_name)
|
| 45 |
+
corpus = build_rag_corpus({"embedding_model": embedding_model_name}, embed_model, website)
|
| 46 |
client = SambaNova(
|
| 47 |
api_key=llm_api_key,
|
| 48 |
base_url="https://api.sambanova.ai/v1",
|
|
|
|
| 50 |
)
|
| 51 |
|
| 52 |
RESOURCE_STATE.update(
|
| 53 |
+
config={"embedding_model": embedding_model_name},
|
| 54 |
website=website,
|
| 55 |
system_prompt=system_prompt,
|
| 56 |
embed_model=embed_model,
|