grvelight commited on
Commit
12d0ffd
Β·
verified Β·
1 Parent(s): 9ecd41e

Update api.py

Browse files
Files changed (1) hide show
  1. api.py +5 -7
api.py CHANGED
@@ -29,13 +29,11 @@ from fastapi.responses import StreamingResponse
29
  from pydantic import BaseModel
30
  from sentence_transformers import SentenceTransformer
31
  from groq import Groq
32
- from huggingface_hub import hf_hub_download
33
- from dotenv import load_dotenv
34
 
35
- # ─────────────────────── LOAD SECRETS ───────────────────
36
- load_dotenv() # reads .env file from current directory
37
 
38
- GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
 
 
39
  HF_REPO_ID = os.environ.get("HF_REPO_ID")
40
 
41
  if not GROQ_API_KEY:
@@ -56,8 +54,8 @@ log.info("Loading model and index from Hugging Face...")
56
  embed_model = SentenceTransformer(EMBED_MODEL)
57
 
58
  # Download index files from HF Hub
59
- index_path = hf_hub_download(repo_id=HF_REPO_ID, filename="index.faiss", repo_type=HF_REPO_TYPE)
60
- chunks_path = hf_hub_download(repo_id=HF_REPO_ID, filename="chunks.json", repo_type=HF_REPO_TYPE)
61
 
62
  faiss_index = faiss.read_index(index_path)
63
  with open(chunks_path, encoding="utf-8") as f:
 
29
  from pydantic import BaseModel
30
  from sentence_transformers import SentenceTransformer
31
  from groq import Groq
 
 
32
 
 
 
33
 
34
+ GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
35
+ if not GROQ_API_KEY:
36
+ raise RuntimeError("❌ GROQ_API_KEY not set")
37
  HF_REPO_ID = os.environ.get("HF_REPO_ID")
38
 
39
  if not GROQ_API_KEY:
 
54
  embed_model = SentenceTransformer(EMBED_MODEL)
55
 
56
  # Download index files from HF Hub
57
+ index_path = "/app/index.faiss"
58
+ chunks_path = "/app/chunks.json"
59
 
60
  faiss_index = faiss.read_index(index_path)
61
  with open(chunks_path, encoding="utf-8") as f: