yamraj047 commited on
Commit
4c6cc6d
·
verified ·
1 Parent(s): 2d34d9a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -19
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
- groq_api_key = os.getenv("GROQ_API_KEY", "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")
 
 
 
 
 
 
 
 
 
91
 
92
  try:
93
- # Try standard initialization
94
  _groq_client = Groq(api_key=groq_api_key)
95
- logger.info("✅ Groq client initialized (standard)")
96
- except TypeError as e:
97
- logger.warning(f"Standard Groq init failed: {e}, trying with custom HTTP client...")
98
- try:
99
- # Fallback with custom HTTP client
100
- http_client = httpx.Client(timeout=60.0)
101
- _groq_client = Groq(
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