Spaces:
Paused
Paused
environment bug
Browse files- app/golf_swing_rag.py +18 -15
- app/models/llm_analyzer.py +8 -7
app/golf_swing_rag.py
CHANGED
|
@@ -208,22 +208,33 @@ class GolfSwingRAG:
|
|
| 208 |
self.metadata = []
|
| 209 |
self.openai_client = None
|
| 210 |
|
| 211 |
-
# Initialize OpenAI client
|
| 212 |
print("Initializing OpenAI client...")
|
| 213 |
openai_key = None
|
| 214 |
|
| 215 |
# Try multiple methods to get the OpenAI API key
|
|
|
|
| 216 |
try:
|
| 217 |
-
|
| 218 |
-
openai_key = st.secrets.get("OPENAI_API_KEY", "")
|
| 219 |
if openai_key:
|
| 220 |
-
print("✓ Found OpenAI key in
|
| 221 |
else:
|
| 222 |
-
print("No key found in
|
| 223 |
except Exception as e:
|
| 224 |
-
print(f"Error accessing
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
|
| 226 |
-
# Method
|
| 227 |
if not openai_key:
|
| 228 |
try:
|
| 229 |
openai_key = st.secrets.get("openai", {}).get("api_key", "")
|
|
@@ -234,14 +245,6 @@ class GolfSwingRAG:
|
|
| 234 |
except Exception as e:
|
| 235 |
print(f"Error accessing nested openai secrets: {e}")
|
| 236 |
|
| 237 |
-
# Method 3: Environment variable fallback
|
| 238 |
-
if not openai_key:
|
| 239 |
-
openai_key = os.getenv("OPENAI_API_KEY", "")
|
| 240 |
-
if openai_key:
|
| 241 |
-
print("✓ Found OpenAI key in environment variable OPENAI_API_KEY")
|
| 242 |
-
else:
|
| 243 |
-
print("No key found in environment variable OPENAI_API_KEY")
|
| 244 |
-
|
| 245 |
# Initialize client if we found a key
|
| 246 |
if openai_key and openai_key.startswith("sk-"):
|
| 247 |
try:
|
|
|
|
| 208 |
self.metadata = []
|
| 209 |
self.openai_client = None
|
| 210 |
|
| 211 |
+
# Initialize OpenAI client - prioritize environment variables for Hugging Face deployment
|
| 212 |
print("Initializing OpenAI client...")
|
| 213 |
openai_key = None
|
| 214 |
|
| 215 |
# Try multiple methods to get the OpenAI API key
|
| 216 |
+
# Method 1: Environment variable (primary for HF Spaces)
|
| 217 |
try:
|
| 218 |
+
openai_key = os.getenv("OPENAI_API_KEY", "")
|
|
|
|
| 219 |
if openai_key:
|
| 220 |
+
print("✓ Found OpenAI key in environment variable OPENAI_API_KEY")
|
| 221 |
else:
|
| 222 |
+
print("No key found in environment variable OPENAI_API_KEY")
|
| 223 |
except Exception as e:
|
| 224 |
+
print(f"Error accessing environment variable OPENAI_API_KEY: {e}")
|
| 225 |
+
|
| 226 |
+
# Method 2: Direct access to OPENAI_API_KEY secret (fallback for Streamlit)
|
| 227 |
+
if not openai_key:
|
| 228 |
+
try:
|
| 229 |
+
openai_key = st.secrets.get("OPENAI_API_KEY", "")
|
| 230 |
+
if openai_key:
|
| 231 |
+
print("✓ Found OpenAI key in st.secrets['OPENAI_API_KEY']")
|
| 232 |
+
else:
|
| 233 |
+
print("No key found in st.secrets['OPENAI_API_KEY']")
|
| 234 |
+
except Exception as e:
|
| 235 |
+
print(f"Error accessing st.secrets['OPENAI_API_KEY']: {e}")
|
| 236 |
|
| 237 |
+
# Method 3: Try nested openai structure (fallback)
|
| 238 |
if not openai_key:
|
| 239 |
try:
|
| 240 |
openai_key = st.secrets.get("openai", {}).get("api_key", "")
|
|
|
|
| 245 |
except Exception as e:
|
| 246 |
print(f"Error accessing nested openai secrets: {e}")
|
| 247 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
# Initialize client if we found a key
|
| 249 |
if openai_key and openai_key.startswith("sk-"):
|
| 250 |
try:
|
app/models/llm_analyzer.py
CHANGED
|
@@ -8,6 +8,7 @@ from openai import OpenAI
|
|
| 8 |
import streamlit as st
|
| 9 |
import re
|
| 10 |
import numpy as np
|
|
|
|
| 11 |
from .pose_estimator import calculate_joint_angles
|
| 12 |
|
| 13 |
|
|
@@ -29,26 +30,26 @@ def check_llm_services():
|
|
| 29 |
}
|
| 30 |
}
|
| 31 |
|
| 32 |
-
# Check Ollama configuration
|
| 33 |
try:
|
| 34 |
-
ollama_url =
|
| 35 |
-
ollama_model =
|
| 36 |
if ollama_url and ollama_model:
|
| 37 |
services['ollama']['available'] = True
|
| 38 |
services['ollama']['config'] = {
|
| 39 |
'base_url': ollama_url,
|
| 40 |
'model': ollama_model
|
| 41 |
}
|
| 42 |
-
except (KeyError,
|
| 43 |
pass
|
| 44 |
|
| 45 |
-
# Check OpenAI configuration
|
| 46 |
try:
|
| 47 |
-
openai_key =
|
| 48 |
if openai_key:
|
| 49 |
services['openai']['available'] = True
|
| 50 |
services['openai']['config'] = {'api_key': openai_key}
|
| 51 |
-
except (KeyError,
|
| 52 |
pass
|
| 53 |
|
| 54 |
return services
|
|
|
|
| 8 |
import streamlit as st
|
| 9 |
import re
|
| 10 |
import numpy as np
|
| 11 |
+
import os
|
| 12 |
from .pose_estimator import calculate_joint_angles
|
| 13 |
|
| 14 |
|
|
|
|
| 30 |
}
|
| 31 |
}
|
| 32 |
|
| 33 |
+
# Check Ollama configuration - read from environment variables
|
| 34 |
try:
|
| 35 |
+
ollama_url = os.environ.get("OLLAMA_BASE_URL", "")
|
| 36 |
+
ollama_model = os.environ.get("OLLAMA_MODEL", "")
|
| 37 |
if ollama_url and ollama_model:
|
| 38 |
services['ollama']['available'] = True
|
| 39 |
services['ollama']['config'] = {
|
| 40 |
'base_url': ollama_url,
|
| 41 |
'model': ollama_model
|
| 42 |
}
|
| 43 |
+
except (KeyError, AttributeError):
|
| 44 |
pass
|
| 45 |
|
| 46 |
+
# Check OpenAI configuration - read from environment variables
|
| 47 |
try:
|
| 48 |
+
openai_key = os.environ.get("OPENAI_API_KEY", "")
|
| 49 |
if openai_key:
|
| 50 |
services['openai']['available'] = True
|
| 51 |
services['openai']['config'] = {'api_key': openai_key}
|
| 52 |
+
except (KeyError, AttributeError):
|
| 53 |
pass
|
| 54 |
|
| 55 |
return services
|