Unggi commited on
Commit
44a3c4d
0 Parent(s):

first commit

Browse files
Files changed (5) hide show
  1. .gitignore +165 -0
  2. README.md +0 -0
  3. requirements.txt +3 -0
  4. src/obs_eval.py +70 -0
  5. src/obs_eval.sh +5 -0
.gitignore ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ datasets/
2
+ model_records/
3
+ config/
4
+ *.env
5
+
6
+ # Byte-compiled / optimized / DLL files
7
+ __pycache__/
8
+ *.py[cod]
9
+ *$py.class
10
+
11
+ # C extensions
12
+ *.so
13
+
14
+ # Distribution / packaging
15
+ .Python
16
+ build/
17
+ develop-eggs/
18
+ dist/
19
+ downloads/
20
+ eggs/
21
+ .eggs/
22
+ lib/
23
+ lib64/
24
+ parts/
25
+ sdist/
26
+ var/
27
+ wheels/
28
+ share/python-wheels/
29
+ *.egg-info/
30
+ .installed.cfg
31
+ *.egg
32
+ MANIFEST
33
+
34
+ # PyInstaller
35
+ # Usually these files are written by a python script from a template
36
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
37
+ *.manifest
38
+ *.spec
39
+
40
+ # Installer logs
41
+ pip-log.txt
42
+ pip-delete-this-directory.txt
43
+
44
+ # Unit test / coverage reports
45
+ htmlcov/
46
+ .tox/
47
+ .nox/
48
+ .coverage
49
+ .coverage.*
50
+ .cache
51
+ nosetests.xml
52
+ coverage.xml
53
+ *.cover
54
+ *.py,cover
55
+ .hypothesis/
56
+ .pytest_cache/
57
+ cover/
58
+
59
+ # Translations
60
+ *.mo
61
+ *.pot
62
+
63
+ # Django stuff:
64
+ *.log
65
+ local_settings.py
66
+ db.sqlite3
67
+ db.sqlite3-journal
68
+
69
+ # Flask stuff:
70
+ instance/
71
+ .webassets-cache
72
+
73
+ # Scrapy stuff:
74
+ .scrapy
75
+
76
+ # Sphinx documentation
77
+ docs/_build/
78
+
79
+ # PyBuilder
80
+ .pybuilder/
81
+ target/
82
+
83
+ # Jupyter Notebook
84
+ .ipynb_checkpoints
85
+
86
+ # IPython
87
+ profile_default/
88
+ ipython_config.py
89
+
90
+ # pyenv
91
+ # For a library or package, you might want to ignore these files since the code is
92
+ # intended to run in multiple environments; otherwise, check them in:
93
+ # .python-version
94
+
95
+ # pipenv
96
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
97
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
98
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
99
+ # install all needed dependencies.
100
+ #Pipfile.lock
101
+
102
+ # poetry
103
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
104
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
105
+ # commonly ignored for libraries.
106
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
107
+ #poetry.lock
108
+
109
+ # pdm
110
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
111
+ #pdm.lock
112
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
113
+ # in version control.
114
+ # https://pdm.fming.dev/#use-with-ide
115
+ .pdm.toml
116
+
117
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
118
+ __pypackages__/
119
+
120
+ # Celery stuff
121
+ celerybeat-schedule
122
+ celerybeat.pid
123
+
124
+ # SageMath parsed files
125
+ *.sage.py
126
+
127
+ # Environments
128
+ .env
129
+ .venv
130
+ env/
131
+ venv/
132
+ ENV/
133
+ env.bak/
134
+ venv.bak/
135
+
136
+ # Spyder project settings
137
+ .spyderproject
138
+ .spyproject
139
+
140
+ # Rope project settings
141
+ .ropeproject
142
+
143
+ # mkdocs documentation
144
+ /site
145
+
146
+ # mypy
147
+ .mypy_cache/
148
+ .dmypy.json
149
+ dmypy.json
150
+
151
+ # Pyre type checker
152
+ .pyre/
153
+
154
+ # pytype static type analyzer
155
+ .pytype/
156
+
157
+ # Cython debug symbols
158
+ cython_debug/
159
+
160
+ # PyCharm
161
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
162
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
163
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
164
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
165
+ #.idea/
README.md ADDED
File without changes
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ openai
2
+ opencv-python
3
+ python-dotenv
src/obs_eval.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import base64
3
+ import time
4
+ import openai
5
+ import requests
6
+ import os
7
+ import argparse
8
+ from dotenv import dotenv_values, load_dotenv
9
+ import time
10
+
11
+ config = dotenv_values("/workspace/Research/PangyoPangyo/src/.env")
12
+
13
+ openai.organization = config.get('OPENAI_ORGANIZATION')
14
+ openai.api_key = config.get('OPENAI_API_KEY')
15
+
16
+ def define_argparser():
17
+ p = argparse.ArgumentParser()
18
+
19
+ p.add_argument("--data_path", type=str, required=True)
20
+
21
+ config = p.parse_args()
22
+
23
+ return config
24
+
25
+
26
+ def main(config):
27
+ # Ensure the dataset directory exists and has the video file
28
+ if not os.path.exists(config.data_path):
29
+ print("Video file not found. Make sure data_path exists.")
30
+ return
31
+
32
+ video = cv2.VideoCapture(config.data_path)
33
+
34
+ base64Frames = []
35
+ while video.isOpened():
36
+ success, frame = video.read()
37
+ if not success:
38
+ break
39
+ _, buffer = cv2.imencode(".jpg", frame)
40
+ base64Frames.append(base64.b64encode(buffer).decode("utf-8"))
41
+
42
+ video.release()
43
+ print(len(base64Frames), "frames read.")
44
+
45
+ # Skipping the display part as it's not relevant in a .py script
46
+
47
+ PROMPT_MESSAGES = [
48
+ {
49
+ "role": "user",
50
+ "content": [
51
+ "These are frames of a video. Create a short voiceover script in the style of a super excited brazilian sports narrator who is narrating his favorite match. He is a big fan of Messi, the player who scores in this clip. Use caps and exclamation marks where needed to communicate excitement. Only include the narration, your output must be in english. When the ball goes into the net, you must scream GOL either once or multiple times.",
52
+ *map(lambda x: {"image": x, "resize": 768}, base64Frames[0::10]),
53
+ ],
54
+ },
55
+ ]
56
+ params = {
57
+ "model": "gpt-4-vision-preview",
58
+ "messages": PROMPT_MESSAGES,
59
+ "api_key": openai.api_key,
60
+ "headers": {"Openai-Version": "2020-11-07"},
61
+ "max_tokens": 500,
62
+ }
63
+
64
+ result = openai.ChatCompletion.create(**params)
65
+ print(result.choices[0].message.content)
66
+
67
+
68
+ if __name__ == "__main__":
69
+ config = define_argparser()
70
+ main(config)
src/obs_eval.sh ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+
2
+
3
+
4
+ python obs_eval.py \
5
+ --data_path "/workspace/Research/gpt_4_vision_for_eval/datasets/messi2.mp4"