Pulastya B commited on
Commit
fde5dd3
·
1 Parent(s): 09cd93c

fix: Support both GOOGLE_API_KEY and GEMINI_API_KEY env vars for HuggingFace compatibility

Browse files
DEPLOYMENT_HUGGINGFACE.md CHANGED
@@ -71,11 +71,19 @@ git push huggingface main
71
  2. Click **Settings** tab
72
  3. Scroll to **Repository secrets**
73
  4. Click **New secret**
74
- 5. Add:
75
  - **Name**: `GEMINI_API_KEY`
76
- - **Value**: Your Google Gemini API key
 
 
 
 
 
 
77
  6. Click **Save**
78
 
 
 
79
  ### Step 6: Wait for Build
80
 
81
  HuggingFace will automatically:
 
71
  2. Click **Settings** tab
72
  3. Scroll to **Repository secrets**
73
  4. Click **New secret**
74
+ 5. Add **both** secrets (code supports both names):
75
  - **Name**: `GEMINI_API_KEY`
76
+ - **Value**: Your Google Gemini API key (from .env file)
77
+ - Click **Add**
78
+
79
+ Also add:
80
+ - **Name**: `LLM_PROVIDER`
81
+ - **Value**: `gemini`
82
+ - Click **Add**
83
  6. Click **Save**
84
 
85
+ **Note**: The code supports both `GOOGLE_API_KEY` and `GEMINI_API_KEY` for compatibility.
86
+
87
  ### Step 6: Wait for Build
88
 
89
  HuggingFace will automatically:
README_SPACES.md CHANGED
@@ -49,13 +49,16 @@ This ensures smooth operation even with large datasets on HuggingFace's 16GB RAM
49
 
50
  ## Environment Variables
51
 
52
- Set `GEMINI_API_KEY` in HuggingFace Spaces settings (Settings → Repository secrets):
53
 
54
- ```
55
- GEMINI_API_KEY=your_google_gemini_api_key_here
56
- ```
 
 
 
57
 
58
- Get your API key from: https://aistudio.google.com/app/apikey
59
 
60
  ## Local Development
61
 
 
49
 
50
  ## Environment Variables
51
 
52
+ Set these in HuggingFace Spaces settings (Settings → Repository secrets):
53
 
54
+ **Required:**
55
+ - `GEMINI_API_KEY` - Your Google Gemini API key (get from https://aistudio.google.com/app/apikey)
56
+ - `LLM_PROVIDER` - Set to `gemini` to use Gemini (or `groq` if you have Groq API key)
57
+
58
+ **Optional:**
59
+ - `GROQ_API_KEY` - Only if using Groq provider instead of Gemini
60
 
61
+ **Note**: The code supports both `GOOGLE_API_KEY` and `GEMINI_API_KEY` environment variable names.
62
 
63
  ## Local Development
64
 
src/api/app.py CHANGED
@@ -365,11 +365,11 @@ async def chat(request: ChatRequest) -> JSONResponse:
365
  latest_message = user_messages[-1].content
366
 
367
  # Check for API key
368
- api_key = os.getenv("GOOGLE_API_KEY")
369
  if not api_key:
370
  raise HTTPException(
371
  status_code=500,
372
- detail="GOOGLE_API_KEY not configured. Please set the environment variable."
373
  )
374
 
375
  # Use Google Gemini API
 
365
  latest_message = user_messages[-1].content
366
 
367
  # Check for API key
368
+ api_key = os.getenv("GOOGLE_API_KEY") or os.getenv("GEMINI_API_KEY")
369
  if not api_key:
370
  raise HTTPException(
371
  status_code=500,
372
+ detail="GOOGLE_API_KEY or GEMINI_API_KEY not configured. Please set the environment variable."
373
  )
374
 
375
  # Use Google Gemini API
src/orchestrator.py CHANGED
@@ -170,9 +170,9 @@ class DataScienceCopilot:
170
 
171
  elif self.provider == "gemini":
172
  # Initialize Gemini client
173
- api_key = google_api_key or os.getenv("GOOGLE_API_KEY")
174
  if not api_key:
175
- raise ValueError("Google API key must be provided or set in GOOGLE_API_KEY env var")
176
 
177
  genai.configure(api_key=api_key)
178
  self.model = os.getenv("GEMINI_MODEL", "gemini-2.0-flash-exp")
 
170
 
171
  elif self.provider == "gemini":
172
  # Initialize Gemini client
173
+ api_key = google_api_key or os.getenv("GOOGLE_API_KEY") or os.getenv("GEMINI_API_KEY")
174
  if not api_key:
175
+ raise ValueError("Google API key must be provided or set in GOOGLE_API_KEY or GEMINI_API_KEY env var")
176
 
177
  genai.configure(api_key=api_key)
178
  self.model = os.getenv("GEMINI_MODEL", "gemini-2.0-flash-exp")