mtoft20 commited on
Commit
8864088
·
verified ·
1 Parent(s): 121b6a5

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +22 -11
src/streamlit_app.py CHANGED
@@ -1,29 +1,40 @@
1
  import streamlit as st
2
  import requests
3
  from together import Together
4
- import json
5
  import os
 
6
 
7
  # =============================================================================
8
  # CONFIGURATION - Using Secrets Management
9
  # =============================================================================
10
- NOCODB_URL = "https://mtoft20-potm.hf.space".strip() # Base URL
11
 
 
12
  def get_api_credentials():
13
- """Get API credentials from secrets"""
14
  try:
15
- # Get credentials from Streamlit secrets
16
- api_token = st.secrets.get("NOCODB_API_TOKEN", "").strip()
17
- together_key = st.secrets.get("TOGETHER_API_KEY", "").strip()
18
- content_endpoint = st.secrets.get("NOCODB_CONTENT_ENDPOINT", "").strip()
 
 
19
  similarity_endpoints = [endpoint.strip() for endpoint in
20
- st.secrets.get("NOCODB_SIMILARITY_ENDPOINTS", "").split(",")
 
 
 
 
 
 
 
 
 
 
 
21
  if endpoint.strip()]
22
 
23
  return api_token, together_key, content_endpoint, similarity_endpoints
24
- except Exception as e:
25
- st.error(f"Error loading credentials: {str(e)}")
26
- return "", "", "", []
27
 
28
  # Initialize Together AI client
29
  @st.cache_resource
 
1
  import streamlit as st
2
  import requests
3
  from together import Together
 
4
  import os
5
+ import json
6
 
7
  # =============================================================================
8
  # CONFIGURATION - Using Secrets Management
9
  # =============================================================================
10
+ NOCODB_URL = "https://mtoft20-potm.hf.space".strip() # Base URL, ensure no extra spaces
11
 
12
+ # Get sensitive data from Streamlit secrets or environment variables
13
  def get_api_credentials():
14
+ """Get API credentials from secrets or environment"""
15
  try:
16
+ # Try Streamlit secrets first (for Hugging Face Spaces)
17
+ api_token = st.secrets.get("NOCODB_API_TOKEN", os.environ.get("NOCODB_API_TOKEN", "")).strip()
18
+ together_key = st.secrets.get("TOGETHER_API_KEY", os.environ.get("TOGETHER_API_KEY", "")).strip()
19
+
20
+ # Get endpoints for content and similarities
21
+ content_endpoint = st.secrets.get("NOCODB_CONTENT_ENDPOINT", os.environ.get("NOCODB_CONTENT_ENDPOINT", "")).strip()
22
  similarity_endpoints = [endpoint.strip() for endpoint in
23
+ st.secrets.get("NOCODB_SIMILARITY_ENDPOINTS",
24
+ os.environ.get("NOCODB_SIMILARITY_ENDPOINTS", "")).split(",")
25
+ if endpoint.strip()]
26
+
27
+ return api_token, together_key, content_endpoint, similarity_endpoints
28
+ except:
29
+ # Fallback to environment variables
30
+ api_token = os.environ.get("NOCODB_API_TOKEN", "").strip()
31
+ together_key = os.environ.get("TOGETHER_API_KEY", "").strip()
32
+ content_endpoint = os.environ.get("NOCODB_CONTENT_ENDPOINT", "").strip()
33
+ similarity_endpoints = [endpoint.strip() for endpoint in
34
+ os.environ.get("NOCODB_SIMILARITY_ENDPOINTS", "").split(",")
35
  if endpoint.strip()]
36
 
37
  return api_token, together_key, content_endpoint, similarity_endpoints
 
 
 
38
 
39
  # Initialize Together AI client
40
  @st.cache_resource