Hashim998 commited on
Commit
9ddc4a0
·
verified ·
1 Parent(s): c722feb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -8
app.py CHANGED
@@ -5,9 +5,7 @@ import time
5
  import gradio as gr
6
  import logging
7
 
8
- # Load local .env only if it exists
9
- from dotenv import load_dotenv
10
- load_dotenv()
11
 
12
  import google.generativeai as genai
13
 
@@ -26,16 +24,16 @@ from langchain_google_genai import ChatGoogleGenerativeAI
26
  logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
27
  logger = logging.getLogger(__name__)
28
 
29
- # Load Gemini API key from Hugging Face secret or local .env
 
30
 
31
- GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
32
  if not GEMINI_API_KEY:
33
- raise ValueError("Missing GEMINI_API_KEY (check Hugging Face secrets or local .env)")
34
 
35
- # Set it in the expected Google API env var
36
  os.environ["GOOGLE_API_KEY"] = GEMINI_API_KEY
37
 
38
- # Configure generativeai
39
  genai.configure(api_key=GEMINI_API_KEY)
40
 
41
 
 
5
  import gradio as gr
6
  import logging
7
 
8
+
 
 
9
 
10
  import google.generativeai as genai
11
 
 
24
  logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
25
  logger = logging.getLogger(__name__)
26
 
27
+ # Pull from Hugging Face Secrets
28
+ GEMINI_API_KEY = os.environ.get("GEMINI_API_KEY")
29
 
 
30
  if not GEMINI_API_KEY:
31
+ raise RuntimeError("GEMINI_API_KEY not found in Hugging Face Secrets")
32
 
33
+ # Ensure it's accessible globally
34
  os.environ["GOOGLE_API_KEY"] = GEMINI_API_KEY
35
 
36
+ # Configure Google GenAI
37
  genai.configure(api_key=GEMINI_API_KEY)
38
 
39