cmulgy commited on
Commit
937d315
Β·
1 Parent(s): c7cb95e
Files changed (3) hide show
  1. GraphRouter_eval/run_exp.py +8 -7
  2. app.py +10 -3
  3. demo.py +9 -9
GraphRouter_eval/run_exp.py CHANGED
@@ -3,11 +3,11 @@ import argparse
3
  import sys
4
  import os
5
 
6
- # Load environment variables from .env file (if it exists)
7
  try:
8
  from dotenv import load_dotenv
9
  load_dotenv()
10
- print("βœ… .env file loaded successfully")
11
  except ImportError:
12
  print("Warning: python-dotenv not installed. Install with: pip install python-dotenv")
13
  print("Or set NVIDIA_API_KEY environment variable manually")
@@ -26,18 +26,19 @@ parser.add_argument("--query", type=str, default="What is the derivative of f(x)
26
  help="Input query to process")
27
  args = parser.parse_args()
28
 
29
- # Load API key from environment variable
30
- NVIDIA_API_KEY = os.getenv("NVIDIA_API_KEY")
31
-
32
- if NVIDIA_API_KEY is None:
33
  print("❌ NVIDIA_API_KEY not found in environment variables")
34
  print("For local development: Create a .env file with: NVIDIA_API_KEY=your_api_key_here")
35
  print("For Hugging Face Spaces: Set NVIDIA_API_KEY in Repository Secrets")
 
36
  sys.exit(1)
37
 
 
 
38
  client = OpenAI(
39
  base_url="https://integrate.api.nvidia.com/v1",
40
- api_key=NVIDIA_API_KEY,
41
  timeout=60,
42
  max_retries=2
43
  )
 
3
  import sys
4
  import os
5
 
6
+ # Load environment variables from .env file (for local development only)
7
  try:
8
  from dotenv import load_dotenv
9
  load_dotenv()
10
+ print("βœ… .env file loaded successfully (local development)")
11
  except ImportError:
12
  print("Warning: python-dotenv not installed. Install with: pip install python-dotenv")
13
  print("Or set NVIDIA_API_KEY environment variable manually")
 
26
  help="Input query to process")
27
  args = parser.parse_args()
28
 
29
+ # Check for API key
30
+ if os.getenv("NVIDIA_API_KEY") is None:
 
 
31
  print("❌ NVIDIA_API_KEY not found in environment variables")
32
  print("For local development: Create a .env file with: NVIDIA_API_KEY=your_api_key_here")
33
  print("For Hugging Face Spaces: Set NVIDIA_API_KEY in Repository Secrets")
34
+ print("⚠️ Exiting due to missing API key")
35
  sys.exit(1)
36
 
37
+ print("βœ… NVIDIA API key loaded from environment")
38
+
39
  client = OpenAI(
40
  base_url="https://integrate.api.nvidia.com/v1",
41
+ api_key=os.getenv("NVIDIA_API_KEY"),
42
  timeout=60,
43
  max_retries=2
44
  )
app.py CHANGED
@@ -24,10 +24,13 @@ def setup_environment():
24
  if os.getenv("SPACE_ID"):
25
  print("πŸš€ Running on Hugging Face Spaces")
26
 
27
- # Set default values for required environment variables
28
  if not os.getenv("NVIDIA_API_KEY"):
29
- print("⚠️ NVIDIA_API_KEY not set. Some features may be limited.")
30
- print(" Please set NVIDIA_API_KEY in the Space settings.")
 
 
 
31
 
32
  # Set CUDA device for Spaces (usually limited resources)
33
  os.environ["CUDA_VISIBLE_DEVICES"] = "0"
@@ -37,6 +40,10 @@ def setup_environment():
37
 
38
  else:
39
  print("🏠 Running locally")
 
 
 
 
40
 
41
  def main():
42
  """Main function to launch the application"""
 
24
  if os.getenv("SPACE_ID"):
25
  print("πŸš€ Running on Hugging Face Spaces")
26
 
27
+ # Check for NVIDIA API key
28
  if not os.getenv("NVIDIA_API_KEY"):
29
+ print("⚠️ NVIDIA_API_KEY not set in Space secrets.")
30
+ print(" Please set NVIDIA_API_KEY in the Space Repository Secrets.")
31
+ print(" Some features may be limited without API access.")
32
+ else:
33
+ print("βœ… NVIDIA_API_KEY found in Space secrets")
34
 
35
  # Set CUDA device for Spaces (usually limited resources)
36
  os.environ["CUDA_VISIBLE_DEVICES"] = "0"
 
40
 
41
  else:
42
  print("🏠 Running locally")
43
+ # Check for local .env file
44
+ if not os.getenv("NVIDIA_API_KEY"):
45
+ print("ℹ️ NVIDIA_API_KEY not found. For local development, create a .env file")
46
+ print(" or set the environment variable manually.")
47
 
48
  def main():
49
  """Main function to launch the application"""
demo.py CHANGED
@@ -43,28 +43,28 @@ import sys
43
  import yaml
44
  from transformers import LongformerTokenizer as RouterTokenizer, LongformerModel as RouterModel
45
 
46
- # Load environment variables from .env file
47
  try:
48
  from dotenv import load_dotenv
49
  load_dotenv()
50
- print("βœ… .env file loaded successfully")
51
  except ImportError:
52
  print("Warning: python-dotenv not installed. Install with: pip install python-dotenv")
53
  print("Or set NVIDIA_API_KEY environment variable manually")
54
  except FileNotFoundError:
55
  print("ℹ️ No .env file found - using environment variables directly")
56
 
57
- # Get API key from environment variable
58
- NVIDIA_API_KEY = os.getenv("NVIDIA_API_KEY")
59
- NVIDIA_BASE_URL = "https://integrate.api.nvidia.com/v1"
60
-
61
- if NVIDIA_API_KEY is None:
62
  print("❌ NVIDIA_API_KEY not found in environment variables")
63
  print("For local development: Create a .env file with: NVIDIA_API_KEY=your_api_key_here")
64
  print("For Hugging Face Spaces: Set NVIDIA_API_KEY in Repository Secrets")
 
65
  else:
66
  print("βœ… NVIDIA API key loaded from environment")
67
 
 
 
68
  # Add GraphRouter_eval to path
69
  sys.path.append(os.path.join(os.path.dirname(__file__), 'GraphRouter_eval/model'))
70
  sys.path.append(os.path.join(os.path.dirname(__file__), 'GraphRouter_eval/data_processing'))
@@ -87,13 +87,13 @@ if torch.cuda.is_available():
87
  print(f"CUDA device name: {torch.cuda.get_device_name(0)}")
88
 
89
  # Initialize OpenAI client for NVIDIA API
90
- if NVIDIA_API_KEY is None:
91
  print("❌ NVIDIA API key not found. Please create a .env file with your API key")
92
  client = None
93
  else:
94
  client = OpenAI(
95
  base_url=NVIDIA_BASE_URL,
96
- api_key=NVIDIA_API_KEY,
97
  timeout=60,
98
  max_retries=2
99
  )
 
43
  import yaml
44
  from transformers import LongformerTokenizer as RouterTokenizer, LongformerModel as RouterModel
45
 
46
+ # Load environment variables from .env file (for local development only)
47
  try:
48
  from dotenv import load_dotenv
49
  load_dotenv()
50
+ print("βœ… .env file loaded successfully (local development)")
51
  except ImportError:
52
  print("Warning: python-dotenv not installed. Install with: pip install python-dotenv")
53
  print("Or set NVIDIA_API_KEY environment variable manually")
54
  except FileNotFoundError:
55
  print("ℹ️ No .env file found - using environment variables directly")
56
 
57
+ # Check for API key
58
+ if os.getenv("NVIDIA_API_KEY") is None:
 
 
 
59
  print("❌ NVIDIA_API_KEY not found in environment variables")
60
  print("For local development: Create a .env file with: NVIDIA_API_KEY=your_api_key_here")
61
  print("For Hugging Face Spaces: Set NVIDIA_API_KEY in Repository Secrets")
62
+ print("⚠️ Some features will be limited without API access")
63
  else:
64
  print("βœ… NVIDIA API key loaded from environment")
65
 
66
+ NVIDIA_BASE_URL = "https://integrate.api.nvidia.com/v1"
67
+
68
  # Add GraphRouter_eval to path
69
  sys.path.append(os.path.join(os.path.dirname(__file__), 'GraphRouter_eval/model'))
70
  sys.path.append(os.path.join(os.path.dirname(__file__), 'GraphRouter_eval/data_processing'))
 
87
  print(f"CUDA device name: {torch.cuda.get_device_name(0)}")
88
 
89
  # Initialize OpenAI client for NVIDIA API
90
+ if os.getenv("NVIDIA_API_KEY") is None:
91
  print("❌ NVIDIA API key not found. Please create a .env file with your API key")
92
  client = None
93
  else:
94
  client = OpenAI(
95
  base_url=NVIDIA_BASE_URL,
96
+ api_key=os.getenv("NVIDIA_API_KEY"),
97
  timeout=60,
98
  max_retries=2
99
  )