Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -34,46 +34,6 @@ RAG_EMBEDDER = None
|
|
| 34 |
client = None
|
| 35 |
REQUIREMENTS_PIPELINE = None
|
| 36 |
|
| 37 |
-
'''
|
| 38 |
-
def load_env_file(env_path: str | None = None):
|
| 39 |
-
"""
|
| 40 |
-
Lightweight .env loader to populate os.environ if keys are missing.
|
| 41 |
-
Falls back to the .env that lives next to this file so launching from
|
| 42 |
-
another working directory still picks up keys.
|
| 43 |
-
"""
|
| 44 |
-
candidate_paths = []
|
| 45 |
-
if env_path:
|
| 46 |
-
candidate_paths.append(env_path)
|
| 47 |
-
else:
|
| 48 |
-
base_dir = os.path.dirname(os.path.abspath(__file__))
|
| 49 |
-
candidate_paths.append(os.path.join(base_dir, ".env"))
|
| 50 |
-
candidate_paths.append(".env")
|
| 51 |
-
|
| 52 |
-
for path in candidate_paths:
|
| 53 |
-
if not os.path.exists(path):
|
| 54 |
-
continue
|
| 55 |
-
try:
|
| 56 |
-
with open(path, "r", encoding="utf-8") as f:
|
| 57 |
-
for line in f:
|
| 58 |
-
line = line.strip()
|
| 59 |
-
if not line or line.startswith("#") or "=" not in line:
|
| 60 |
-
continue
|
| 61 |
-
key, value = line.split("=", 1)
|
| 62 |
-
if key and key not in os.environ:
|
| 63 |
-
os.environ[key] = value
|
| 64 |
-
print(f"Loaded environment variables from {path}")
|
| 65 |
-
return
|
| 66 |
-
except Exception as exc:
|
| 67 |
-
print(f"Warning: failed to load {path}: {exc}")
|
| 68 |
-
|
| 69 |
-
# Load .env early so API keys (e.g., OPENROUTER_API_KEY) are available.
|
| 70 |
-
load_env_file()
|
| 71 |
-
'''
|
| 72 |
-
# HF Spaces: load API keys from Secrets only
|
| 73 |
-
OPENROUTER_API_KEY = os.getenv("OPENROUTER_API_KEY")
|
| 74 |
-
if not OPENROUTER_API_KEY:
|
| 75 |
-
print("WARNING: No API key found. Add one in Settings → Secrets.")
|
| 76 |
-
|
| 77 |
MAX_CONTEXT_FILE_SIZE = 2 * 1024 * 1024 # 2 MB
|
| 78 |
MAX_CONTEXT_FILE_CHARACTERS = 6000
|
| 79 |
SUPPORTED_CONTEXT_FILE_EXTENSIONS = {".txt", ".md", ".json", ".csv", ".pdf"}
|
|
@@ -999,8 +959,8 @@ def ensure_pipeline_initialized():
|
|
| 999 |
init_rag_if_needed()
|
| 1000 |
retriever = ChromaRetriever(RAG_COLLECTION, n_results=RAG_N_RESULTS)
|
| 1001 |
summarizer = LocalSummarizer()
|
| 1002 |
-
router = RequirementsRouter()
|
| 1003 |
-
jira_agent = JiraAgent()
|
| 1004 |
matrix_agent = ComplianceMatrixAgent()
|
| 1005 |
REQUIREMENTS_PIPELINE = RequirementsPipeline(
|
| 1006 |
rag_model=RequirementsRAGModel(retriever=retriever, llm=summarizer),
|
|
|
|
| 34 |
client = None
|
| 35 |
REQUIREMENTS_PIPELINE = None
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
MAX_CONTEXT_FILE_SIZE = 2 * 1024 * 1024 # 2 MB
|
| 38 |
MAX_CONTEXT_FILE_CHARACTERS = 6000
|
| 39 |
SUPPORTED_CONTEXT_FILE_EXTENSIONS = {".txt", ".md", ".json", ".csv", ".pdf"}
|
|
|
|
| 959 |
init_rag_if_needed()
|
| 960 |
retriever = ChromaRetriever(RAG_COLLECTION, n_results=RAG_N_RESULTS)
|
| 961 |
summarizer = LocalSummarizer()
|
| 962 |
+
router = RequirementsRouter(api_key=api_key)
|
| 963 |
+
jira_agent = JiraAgent(api_key=api_key)
|
| 964 |
matrix_agent = ComplianceMatrixAgent()
|
| 965 |
REQUIREMENTS_PIPELINE = RequirementsPipeline(
|
| 966 |
rag_model=RequirementsRAGModel(retriever=retriever, llm=summarizer),
|