Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -83,32 +83,32 @@ def get_cross_encoder():
|
|
| 83 |
logger.info("✅ Cross-encoder loaded successfully")
|
| 84 |
return _cross_encoder
|
| 85 |
|
|
|
|
|
|
|
| 86 |
def get_groq_client():
|
| 87 |
global _groq_client
|
| 88 |
if _groq_client is None:
|
| 89 |
logger.info("Initializing Groq client...")
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
try:
|
| 93 |
-
# Try standard initialization
|
| 94 |
_groq_client = Groq(api_key=groq_api_key)
|
| 95 |
-
logger.info("✅ Groq client initialized
|
| 96 |
-
except
|
| 97 |
-
logger.
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
api_key=groq_api_key,
|
| 103 |
-
http_client=http_client
|
| 104 |
-
)
|
| 105 |
-
logger.info("✅ Groq client initialized (with custom HTTP client)")
|
| 106 |
-
except Exception as e2:
|
| 107 |
-
logger.error(f"❌ Failed to initialize Groq client: {e2}")
|
| 108 |
-
raise HTTPException(
|
| 109 |
-
status_code=503,
|
| 110 |
-
detail=f"Failed to initialize Groq client: {str(e2)}"
|
| 111 |
-
)
|
| 112 |
|
| 113 |
return _groq_client
|
| 114 |
|
|
|
|
| 83 |
logger.info("✅ Cross-encoder loaded successfully")
|
| 84 |
return _cross_encoder
|
| 85 |
|
| 86 |
+
|
| 87 |
+
|
| 88 |
def get_groq_client():
|
| 89 |
global _groq_client
|
| 90 |
if _groq_client is None:
|
| 91 |
logger.info("Initializing Groq client...")
|
| 92 |
+
|
| 93 |
+
# Get API key from environment ONLY (no fallback)
|
| 94 |
+
groq_api_key = os.getenv("GROQ_API_KEY")
|
| 95 |
+
|
| 96 |
+
if not groq_api_key:
|
| 97 |
+
logger.error("❌ GROQ_API_KEY not found in environment")
|
| 98 |
+
raise HTTPException(
|
| 99 |
+
status_code=503,
|
| 100 |
+
detail="GROQ_API_KEY not configured. Please set it in Hugging Face Space secrets."
|
| 101 |
+
)
|
| 102 |
|
| 103 |
try:
|
|
|
|
| 104 |
_groq_client = Groq(api_key=groq_api_key)
|
| 105 |
+
logger.info("✅ Groq client initialized successfully")
|
| 106 |
+
except Exception as e:
|
| 107 |
+
logger.error(f"❌ Failed to initialize Groq client: {e}")
|
| 108 |
+
raise HTTPException(
|
| 109 |
+
status_code=503,
|
| 110 |
+
detail=f"Failed to initialize Groq client: {str(e)}"
|
| 111 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
return _groq_client
|
| 114 |
|