Skip to content

Commit 2b0ef1d

Browse files
VividhDesignclaude
andcommitted
Streamlit Community Cloud deployment
- requirements.txt (CPU-only torch, Strata from GitHub) and packages.txt (C++ toolchain) - app auto-detects Streamlit Cloud: Groq provider, API key from Streamlit secrets, precomputed embeddings fetched from the vividh111/evident-demo-data dataset Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 5167cb6 commit 2b0ef1d

3 files changed

Lines changed: 55 additions & 6 deletions

File tree

‎app.py‎

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,34 @@
1111
import os
1212
import re
1313
import time
14+
from pathlib import Path
1415

1516
import numpy as np
1617
import pandas as pd
1718
import streamlit as st
1819

19-
from evident import config
20-
from evident.data import load_beir
21-
from evident.ingest import list_corpora, load_corpus
22-
from evident.llm import LLM, PROVIDERS
23-
from evident.rag import RAG
24-
from evident.retriever import MODES, Retriever
20+
# Streamlit Community Cloud checks the repo out under /mount/src. The hosted settings must be in
21+
# the environment before evident.config is imported.
22+
ON_STREAMLIT_CLOUD = Path(__file__).resolve().as_posix().startswith("/mount/src/")
23+
HOSTED = os.environ.get("EVIDENT_HOSTED") == "1" or ON_STREAMLIT_CLOUD
24+
DEMO_DATA_REPO = "vividh111/evident-demo-data" # precomputed embeddings (Hugging Face dataset)
25+
if HOSTED:
26+
os.environ.setdefault("EVIDENT_DATA", str(Path.home() / ".cache" / "evident-demo"))
27+
os.environ.setdefault("EVIDENT_LLM_PROVIDER", "groq")
28+
os.environ.setdefault("EVIDENT_LLM_MODEL", "llama-3.1-8b-instant")
29+
try: # Streamlit secrets -> environment, for the LLM client
30+
for key in ("GROQ_API_KEY", "GEMINI_API_KEY", "OPENAI_API_KEY"):
31+
if key in st.secrets and not os.environ.get(key):
32+
os.environ[key] = str(st.secrets[key])
33+
except Exception: # no secrets configured
34+
pass
35+
36+
from evident import config # noqa: E402
37+
from evident.data import load_beir # noqa: E402
38+
from evident.ingest import list_corpora, load_corpus # noqa: E402
39+
from evident.llm import LLM, PROVIDERS # noqa: E402
40+
from evident.rag import RAG # noqa: E402
41+
from evident.retriever import MODES, Retriever # noqa: E402
2542

2643
HOSTED = os.environ.get("EVIDENT_HOSTED") == "1"
2744
QUESTION_LIMIT = 20 # per browser session on the hosted demo (protects the free API quota)
@@ -32,6 +49,21 @@
3249
st.set_page_config(page_title="Evident + Strata demo", layout="wide")
3350

3451

52+
@st.cache_resource(show_spinner="Downloading precomputed embeddings (first start only)...")
53+
def ensure_demo_data() -> None:
54+
"""On the hosted demo, fetch document embeddings instead of recomputing them on a small CPU.
55+
The BEIR corpora themselves are downloaded from their original source on first use."""
56+
if not HOSTED or any((config.CACHE_DIR / "embeddings").glob("*.npy")):
57+
return
58+
from huggingface_hub import snapshot_download
59+
60+
snapshot_download(DEMO_DATA_REPO, repo_type="dataset", local_dir=str(config.DATA_DIR),
61+
allow_patterns=["cache/*", "indexes/*"])
62+
63+
64+
ensure_demo_data()
65+
66+
3567
# ---------------------------------------------------------------------------------------------
3668
# Cached resources
3769
# ---------------------------------------------------------------------------------------------

‎packages.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build-essential
2+
cmake

‎requirements.txt‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Streamlit Community Cloud installs these (the app is app.py; the `evident` package is imported
2+
# straight from this repository). Local development: pip install -e ".[app,dev]" instead.
3+
--extra-index-url https://download.pytorch.org/whl/cpu
4+
torch
5+
strata-vdb @ git+https://github.com/VividhDesign/strata
6+
numpy
7+
scipy
8+
PyStemmer
9+
sentence-transformers
10+
httpx
11+
pypdf
12+
streamlit
13+
pandas
14+
altair
15+
huggingface_hub

0 commit comments

Comments
 (0)