Skip to content

Commit 39037dd

Browse files
support load_env
1 parent db460d1 commit 39037dd

File tree

6 files changed

+33
-1
lines changed

6 files changed

+33
-1
lines changed

.env

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Development Setting
2+
INTERNAL=
3+
ALLES=
4+
DASHSCOPE_API_KEY=
5+
GOOGLE_API_KEY=
6+
OPENAI_API_KEY=
7+
OPENAI_API_BASE=

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ celerybeat.pid
120120
*.sage.py
121121

122122
# Environments
123-
.env
123+
# .env
124124
.venv
125125
env/
126126
venv/

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pandas>=1.5.3
1111
pillow
1212
portalocker
1313
pycocoevalcap
14+
python-dotenv
1415
requests
1516
rich
1617
seaborn

run.py

+1
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,5 @@ def main():
144144

145145

146146
if __name__ == '__main__':
147+
load_env()
147148
main()

vlmeval/evaluate/misc.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import os
22
from vlmeval.api import OpenAIWrapper, OpenAIWrapperInternal
3+
from vlmeval.smp import load_env
34

45
INTERNAL = os.environ.get('INTERNAL', 0)
56

67

78
def build_judge(version, **kwargs):
9+
load_env()
810
model_map = {
911
'gpt-4-turbo': 'gpt-4-1106-preview',
1012
'gpt-4-0613': 'gpt-4-0613',

vlmeval/smp/misc.py

+21
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,24 @@ def run_command(cmd):
147147
if isinstance(cmd, str):
148148
cmd = cmd.split()
149149
return subprocess.check_output(cmd)
150+
151+
def load_env():
152+
try:
153+
import vlmeval
154+
except ImportError:
155+
warnings.warn('VLMEval is not installed. Failed to import environment variables from .env file. ')
156+
return
157+
pth = osp.realpath(vlmeval.__path__)
158+
pth = osp.join('../.env')
159+
pth = osp.realpath(pth)
160+
if not osp.exists(pth):
161+
warnings.warn(f'Did not detect the .env file at {pth}, failed to load. ')
162+
return
163+
164+
from dotenv import dotenv_values
165+
values = dotenv_values(pth)
166+
for k, v in values.items():
167+
if v is not None and len(v):
168+
os.environ[k] = v
169+
print(f'API Keys successfully loaded from {pth}')
170+
return

0 commit comments

Comments
 (0)