mtoft20 commited on
Commit
e62cc90
·
verified ·
1 Parent(s): f540cd0

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +10 -22
src/streamlit_app.py CHANGED
@@ -1,40 +1,28 @@
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
 
1
  import streamlit as st
2
  import requests
3
  from together import Together
 
4
  import json
5
 
6
  # =============================================================================
7
  # CONFIGURATION - Using Secrets Management
8
  # =============================================================================
9
+ NOCODB_URL = "https://mtoft20-potm.hf.space".strip() # Base URL
10
 
 
11
  def get_api_credentials():
12
+ """Get API credentials from secrets"""
13
  try:
14
+ # Get credentials from Streamlit secrets
15
+ api_token = st.secrets.get("NOCODB_API_TOKEN", "").strip()
16
+ together_key = st.secrets.get("TOGETHER_API_KEY", "").strip()
17
+ content_endpoint = st.secrets.get("NOCODB_CONTENT_ENDPOINT", "").strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  similarity_endpoints = [endpoint.strip() for endpoint in
19
+ st.secrets.get("NOCODB_SIMILARITY_ENDPOINTS", "").split(",")
20
  if endpoint.strip()]
21
 
22
  return api_token, together_key, content_endpoint, similarity_endpoints
23
+ except Exception as e:
24
+ st.error(f"Error loading credentials: {str(e)}")
25
+ return "", "", "", []
26
 
27
  # Initialize Together AI client
28
  @st.cache_resource