mtoft20 commited on
Commit
9647cd9
·
verified ·
1 Parent(s): 462a5cc

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +17 -12
src/streamlit_app.py CHANGED
@@ -8,27 +8,32 @@ import json
8
  # =============================================================================
9
  # CONFIGURATION - Using Secrets Management
10
  # =============================================================================
11
- NOCODB_URL = "https://mtoft20-potm.hf.space" # Base URL
12
 
13
  # Get sensitive data from Streamlit secrets or environment variables
14
  def get_api_credentials():
15
  """Get API credentials from secrets or environment"""
16
  try:
17
  # Try Streamlit secrets first (for Hugging Face Spaces)
18
- api_token = st.secrets.get("NOCODB_API_TOKEN", os.environ.get("NOCODB_API_TOKEN", ""))
19
- together_key = st.secrets.get("TOGETHER_API_KEY", os.environ.get("TOGETHER_API_KEY", ""))
20
 
21
  # Get endpoints for content and similarities
22
- content_endpoint = st.secrets.get("NOCODB_CONTENT_ENDPOINT", os.environ.get("NOCODB_CONTENT_ENDPOINT", ""))
23
- similarity_endpoints = st.secrets.get("NOCODB_SIMILARITY_ENDPOINTS", os.environ.get("NOCODB_SIMILARITY_ENDPOINTS", "")).split(",")
 
 
 
24
 
25
  return api_token, together_key, content_endpoint, similarity_endpoints
26
  except:
27
  # Fallback to environment variables
28
- api_token = os.environ.get("NOCODB_API_TOKEN", "")
29
- together_key = os.environ.get("TOGETHER_API_KEY", "")
30
- content_endpoint = os.environ.get("NOCODB_CONTENT_ENDPOINT", "")
31
- similarity_endpoints = os.environ.get("NOCODB_SIMILARITY_ENDPOINTS", "").split(",")
 
 
32
 
33
  return api_token, together_key, content_endpoint, similarity_endpoints
34
 
@@ -66,7 +71,7 @@ def get_streaming_content():
66
  try:
67
  while True:
68
  offset = (page - 1) * page_size
69
- url = f"{NOCODB_URL}{content_endpoint}?limit={page_size}&offset={offset}"
70
 
71
  response = requests.get(url, headers=headers)
72
 
@@ -280,7 +285,7 @@ def get_similar_content(content, n_recommendations=5):
280
  continue
281
 
282
  try:
283
- url = f"{NOCODB_URL}{endpoint}"
284
  response = requests.get(url, headers=headers, params=params)
285
 
286
  if response.status_code == 200:
@@ -298,7 +303,7 @@ def get_similar_content(content, n_recommendations=5):
298
  content_params = {
299
  "where": query
300
  }
301
- content_url = f"{NOCODB_URL}{content_endpoint}"
302
  content_response = requests.get(content_url, headers=headers, params=content_params)
303
 
304
  if content_response.status_code == 200:
 
8
  # =============================================================================
9
  # CONFIGURATION - Using Secrets Management
10
  # =============================================================================
11
+ NOCODB_URL = "https://mtoft20-potm.hf.space".strip() # Base URL, ensure no extra spaces
12
 
13
  # Get sensitive data from Streamlit secrets or environment variables
14
  def get_api_credentials():
15
  """Get API credentials from secrets or environment"""
16
  try:
17
  # Try Streamlit secrets first (for Hugging Face Spaces)
18
+ api_token = st.secrets.get("NOCODB_API_TOKEN", os.environ.get("NOCODB_API_TOKEN", "")).strip()
19
+ together_key = st.secrets.get("TOGETHER_API_KEY", os.environ.get("TOGETHER_API_KEY", "")).strip()
20
 
21
  # Get endpoints for content and similarities
22
+ content_endpoint = st.secrets.get("NOCODB_CONTENT_ENDPOINT", os.environ.get("NOCODB_CONTENT_ENDPOINT", "")).strip()
23
+ similarity_endpoints = [endpoint.strip() for endpoint in
24
+ st.secrets.get("NOCODB_SIMILARITY_ENDPOINTS",
25
+ os.environ.get("NOCODB_SIMILARITY_ENDPOINTS", "")).split(",")
26
+ if endpoint.strip()]
27
 
28
  return api_token, together_key, content_endpoint, similarity_endpoints
29
  except:
30
  # Fallback to environment variables
31
+ api_token = os.environ.get("NOCODB_API_TOKEN", "").strip()
32
+ together_key = os.environ.get("TOGETHER_API_KEY", "").strip()
33
+ content_endpoint = os.environ.get("NOCODB_CONTENT_ENDPOINT", "").strip()
34
+ similarity_endpoints = [endpoint.strip() for endpoint in
35
+ os.environ.get("NOCODB_SIMILARITY_ENDPOINTS", "").split(",")
36
+ if endpoint.strip()]
37
 
38
  return api_token, together_key, content_endpoint, similarity_endpoints
39
 
 
71
  try:
72
  while True:
73
  offset = (page - 1) * page_size
74
+ url = f"{NOCODB_URL.strip()}{content_endpoint.strip()}?limit={page_size}&offset={offset}"
75
 
76
  response = requests.get(url, headers=headers)
77
 
 
285
  continue
286
 
287
  try:
288
+ url = f"{NOCODB_URL.strip()}{endpoint.strip()}"
289
  response = requests.get(url, headers=headers, params=params)
290
 
291
  if response.status_code == 200:
 
303
  content_params = {
304
  "where": query
305
  }
306
+ content_url = f"{NOCODB_URL.strip()}{content_endpoint.strip()}"
307
  content_response = requests.get(content_url, headers=headers, params=content_params)
308
 
309
  if content_response.status_code == 200: