Spaces:
Running
Running
Commit
•
f51c1fd
1
Parent(s):
e17ec0b
Summary
Browse files- .flake8 +5 -0
- .gitignore +172 -0
- LICENSE +21 -0
- README.md +4 -4
- app.css +67 -0
- app.py +39 -0
- app/__init__.py +0 -0
- app/authors.py +10 -0
- app/components.py +94 -0
- app/config.py +38 -0
- app/description.py +17 -0
- app/event_handlers/__init__.py +0 -0
- app/event_handlers/calculate_pt_scores_blocks.py +31 -0
- app/event_handlers/clear_blocks.py +32 -0
- app/event_handlers/event_handlers.py +56 -0
- app/event_handlers/files.py +44 -0
- app/oceanai_init.py +75 -0
- app/tabs.py +50 -0
- config.toml +16 -0
- requirements.txt +5 -0
.flake8
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
; https://www.flake8rules.com/
|
2 |
+
|
3 |
+
[flake8]
|
4 |
+
max-line-length = 120
|
5 |
+
ignore = E203, E402, E741, W503
|
.gitignore
ADDED
@@ -0,0 +1,172 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Compiled source #
|
2 |
+
###################
|
3 |
+
*.com
|
4 |
+
*.class
|
5 |
+
*.dll
|
6 |
+
*.exe
|
7 |
+
*.o
|
8 |
+
*.so
|
9 |
+
*.pyc
|
10 |
+
|
11 |
+
# Packages #
|
12 |
+
############
|
13 |
+
# it's better to unpack these files and commit the raw source
|
14 |
+
# git has its own built in compression methods
|
15 |
+
*.7z
|
16 |
+
*.dmg
|
17 |
+
*.gz
|
18 |
+
*.iso
|
19 |
+
*.rar
|
20 |
+
#*.tar
|
21 |
+
*.zip
|
22 |
+
|
23 |
+
# Logs and databases #
|
24 |
+
######################
|
25 |
+
*.log
|
26 |
+
*.sqlite
|
27 |
+
|
28 |
+
# OS generated files #
|
29 |
+
######################
|
30 |
+
.DS_Store
|
31 |
+
ehthumbs.db
|
32 |
+
Icon
|
33 |
+
Thumbs.db
|
34 |
+
.tmtags
|
35 |
+
.idea
|
36 |
+
.vscode
|
37 |
+
tags
|
38 |
+
vendor.tags
|
39 |
+
tmtagsHistory
|
40 |
+
*.sublime-project
|
41 |
+
*.sublime-workspace
|
42 |
+
.bundle
|
43 |
+
|
44 |
+
# Byte-compiled / optimized / DLL files
|
45 |
+
__pycache__/
|
46 |
+
*.py[cod]
|
47 |
+
*$py.class
|
48 |
+
|
49 |
+
# C extensions
|
50 |
+
*.so
|
51 |
+
|
52 |
+
# Distribution / packaging
|
53 |
+
.Python
|
54 |
+
build/
|
55 |
+
develop-eggs/
|
56 |
+
dist/
|
57 |
+
downloads/
|
58 |
+
eggs/
|
59 |
+
.eggs/
|
60 |
+
lib/
|
61 |
+
lib64/
|
62 |
+
parts/
|
63 |
+
sdist/
|
64 |
+
var/
|
65 |
+
wheels/
|
66 |
+
pip-wheel-metadata/
|
67 |
+
share/python-wheels/
|
68 |
+
*.egg-info/
|
69 |
+
.installed.cfg
|
70 |
+
*.egg
|
71 |
+
MANIFEST
|
72 |
+
node_modules/
|
73 |
+
|
74 |
+
# PyInstaller
|
75 |
+
# Usually these files are written by a python script from a template
|
76 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
77 |
+
*.manifest
|
78 |
+
*.spec
|
79 |
+
|
80 |
+
# Installer logs
|
81 |
+
pip-log.txt
|
82 |
+
pip-delete-this-directory.txt
|
83 |
+
|
84 |
+
# Unit test / coverage reports
|
85 |
+
htmlcov/
|
86 |
+
.tox/
|
87 |
+
.nox/
|
88 |
+
.coverage
|
89 |
+
.coverage.*
|
90 |
+
.cache
|
91 |
+
nosetests.xml
|
92 |
+
coverage.xml
|
93 |
+
*.cover
|
94 |
+
.hypothesis/
|
95 |
+
.pytest_cache/
|
96 |
+
|
97 |
+
# Translations
|
98 |
+
*.mo
|
99 |
+
*.pot
|
100 |
+
|
101 |
+
# Django stuff:
|
102 |
+
*.log
|
103 |
+
local_settings.py
|
104 |
+
db.sqlite3
|
105 |
+
db.sqlite3-journal
|
106 |
+
|
107 |
+
# Flask stuff:
|
108 |
+
instance/
|
109 |
+
.webassets-cache
|
110 |
+
|
111 |
+
# Scrapy stuff:
|
112 |
+
.scrapy
|
113 |
+
|
114 |
+
# Sphinx documentation
|
115 |
+
docs/_build/
|
116 |
+
|
117 |
+
# PyBuilder
|
118 |
+
target/
|
119 |
+
|
120 |
+
# Jupyter Notebook
|
121 |
+
.ipynb_checkpoints
|
122 |
+
|
123 |
+
# IPython
|
124 |
+
profile_default/
|
125 |
+
ipython_config.py
|
126 |
+
|
127 |
+
# pyenv
|
128 |
+
.python-version
|
129 |
+
|
130 |
+
# pipenv
|
131 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
132 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
133 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
134 |
+
# install all needed dependencies.
|
135 |
+
#Pipfile.lock
|
136 |
+
|
137 |
+
# celery beat schedule file
|
138 |
+
celerybeat-schedule
|
139 |
+
|
140 |
+
# SageMath parsed files
|
141 |
+
*.sage.py
|
142 |
+
|
143 |
+
# Environments
|
144 |
+
.env
|
145 |
+
.venv
|
146 |
+
env/
|
147 |
+
venv/
|
148 |
+
ENV/
|
149 |
+
env.bak/
|
150 |
+
venv.bak/
|
151 |
+
|
152 |
+
# Spyder project settings
|
153 |
+
.spyderproject
|
154 |
+
.spyproject
|
155 |
+
|
156 |
+
# Rope project settings
|
157 |
+
.ropeproject
|
158 |
+
|
159 |
+
# mkdocs documentation
|
160 |
+
/site
|
161 |
+
|
162 |
+
# mypy
|
163 |
+
.mypy_cache/
|
164 |
+
.dmypy.json
|
165 |
+
dmypy.json
|
166 |
+
|
167 |
+
# Pyre type checker
|
168 |
+
.pyre/
|
169 |
+
|
170 |
+
# Custom
|
171 |
+
logs/
|
172 |
+
models/
|
LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
MIT License
|
2 |
+
|
3 |
+
Copyright (c) 2024 Elena Ryumina and Dmitry Ryumin
|
4 |
+
|
5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6 |
+
of this software and associated documentation files (the "Software"), to deal
|
7 |
+
in the Software without restriction, including without limitation the rights
|
8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9 |
+
copies of the Software, and to permit persons to whom the Software is
|
10 |
+
furnished to do so, subject to the following conditions:
|
11 |
+
|
12 |
+
The above copyright notice and this permission notice shall be included in all
|
13 |
+
copies or substantial portions of the Software.
|
14 |
+
|
15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21 |
+
SOFTWARE.
|
README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
---
|
2 |
title: OCEANAI
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.24.0
|
8 |
app_file: app.py
|
@@ -10,4 +10,4 @@ pinned: false
|
|
10 |
license: mit
|
11 |
---
|
12 |
|
13 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
title: OCEANAI
|
3 |
+
emoji: 🤩🔝🔥
|
4 |
+
colorFrom: gray
|
5 |
+
colorTo: red
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.24.0
|
8 |
app_file: app.py
|
|
|
10 |
license: mit
|
11 |
---
|
12 |
|
13 |
+
Check out the configuration reference at <https://huggingface.co/docs/hub/spaces-config-reference>
|
app.css
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.noti_err {
|
2 |
+
color: #B42E2C;
|
3 |
+
}
|
4 |
+
.noti_true {
|
5 |
+
color: #006900;
|
6 |
+
}
|
7 |
+
|
8 |
+
div.video-container {
|
9 |
+
height: 350px;
|
10 |
+
max-height: 350px;
|
11 |
+
}
|
12 |
+
|
13 |
+
div.files-container {
|
14 |
+
height: 350px;
|
15 |
+
max-height: 350px;
|
16 |
+
}
|
17 |
+
|
18 |
+
div.files-container div.file-preview-holder {
|
19 |
+
overflow-y: scroll;
|
20 |
+
height: 100%;
|
21 |
+
}
|
22 |
+
|
23 |
+
div.files-container label[data-testid="block-label"] {
|
24 |
+
position: absolute;
|
25 |
+
}
|
26 |
+
|
27 |
+
.calculate_oceanai {
|
28 |
+
display: inline-block;
|
29 |
+
padding: 10px 20px;
|
30 |
+
font-size: 16px;
|
31 |
+
font-weight: bold;
|
32 |
+
text-align: center;
|
33 |
+
text-decoration: none;
|
34 |
+
cursor: pointer;
|
35 |
+
border: var(--button-border-width) solid var(--button-primary-border-color);
|
36 |
+
background: var(--button-primary-background-fill);
|
37 |
+
color: var(--button-primary-text-color);
|
38 |
+
border-radius: 8px;
|
39 |
+
transition: all 0.3s ease;
|
40 |
+
}
|
41 |
+
|
42 |
+
.clear_oceanai {
|
43 |
+
display: inline-block;
|
44 |
+
padding: 10px 20px;
|
45 |
+
font-size: 16px;
|
46 |
+
font-weight: bold;
|
47 |
+
text-align: center;
|
48 |
+
text-decoration: none;
|
49 |
+
cursor: pointer;
|
50 |
+
border-radius: 8px;
|
51 |
+
transition: all 0.3s ease;
|
52 |
+
}
|
53 |
+
|
54 |
+
.calculate_oceanai[disabled], .clear_oceanai[disabled] {
|
55 |
+
cursor: not-allowed;
|
56 |
+
opacity: 0.6;
|
57 |
+
}
|
58 |
+
|
59 |
+
.calculate_oceanai:hover:not([disabled]) {
|
60 |
+
border-color: var(--button-primary-border-color-hover);
|
61 |
+
background: var(--button-primary-background-fill-hover);
|
62 |
+
color: var(--button-primary-text-color-hover);
|
63 |
+
}
|
64 |
+
|
65 |
+
.calculate_oceanai:active:not([disabled]), .clear_oceanai:active:not([disabled]) {
|
66 |
+
transform: scale(0.98);
|
67 |
+
}
|
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
File: app.py
|
3 |
+
Authors: Elena Ryumina and Dmitry Ryumin
|
4 |
+
Description: OCEANAI App for gradio.
|
5 |
+
License: MIT License
|
6 |
+
"""
|
7 |
+
|
8 |
+
import gradio as gr
|
9 |
+
|
10 |
+
# Importing necessary components for the Gradio app
|
11 |
+
from app.config import CONFIG_NAME, config_data, load_tab_creators
|
12 |
+
from app.event_handlers.event_handlers import setup_app_event_handlers
|
13 |
+
from app import tabs
|
14 |
+
|
15 |
+
|
16 |
+
def create_gradio_app() -> gr.Blocks:
|
17 |
+
with gr.Blocks(css=config_data.AppSettings_CSS_PATH) as gradio_app:
|
18 |
+
tab_results = {}
|
19 |
+
|
20 |
+
available_functions = {
|
21 |
+
attr: getattr(tabs, attr)
|
22 |
+
for attr in dir(tabs)
|
23 |
+
if callable(getattr(tabs, attr)) and attr.endswith("_tab")
|
24 |
+
}
|
25 |
+
|
26 |
+
tab_creators = load_tab_creators(CONFIG_NAME, available_functions)
|
27 |
+
|
28 |
+
for tab_name, create_tab_function in tab_creators.items():
|
29 |
+
with gr.Tab(tab_name):
|
30 |
+
app_instance = create_tab_function()
|
31 |
+
tab_results[tab_name] = app_instance
|
32 |
+
|
33 |
+
setup_app_event_handlers(*tab_results[list(tab_results.keys())[0]])
|
34 |
+
|
35 |
+
return gradio_app
|
36 |
+
|
37 |
+
|
38 |
+
if __name__ == "__main__":
|
39 |
+
create_gradio_app().queue(api_open=False).launch(share=True)
|
app/__init__.py
ADDED
File without changes
|
app/authors.py
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
File: authors.py
|
3 |
+
Author: Elena Ryumina and Dmitry Ryumin
|
4 |
+
Description: About the authors.
|
5 |
+
License: MIT License
|
6 |
+
"""
|
7 |
+
|
8 |
+
AUTHORS = """
|
9 |
+
Authors: [Elena Ryumina](https://github.com/ElenaRyumina), [Dmitry Ryumin](https://github.com/DmitryRyumin)
|
10 |
+
"""
|
app/components.py
ADDED
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
File: components.py
|
3 |
+
Author: Elena Ryumina and Dmitry Ryumin
|
4 |
+
Description: Utility functions for creating Gradio components.
|
5 |
+
License: MIT License
|
6 |
+
"""
|
7 |
+
|
8 |
+
import gradio as gr
|
9 |
+
from typing import Union, List, Callable, Optional
|
10 |
+
|
11 |
+
|
12 |
+
def html_message(
|
13 |
+
message: str = "", error: bool = True, visible: bool = True
|
14 |
+
) -> gr.HTML:
|
15 |
+
css_class = "noti_err" if not error else "noti_true"
|
16 |
+
|
17 |
+
return gr.HTML(value=f"<h3 class='{css_class}'>{message}</h3>", visible=visible)
|
18 |
+
|
19 |
+
|
20 |
+
def files_create_ui(
|
21 |
+
value: Union[str, List[str], Callable, None] = None,
|
22 |
+
file_count: str = "multiple",
|
23 |
+
file_types: List = ["video"],
|
24 |
+
label: str = "Video Files",
|
25 |
+
show_label: bool = True,
|
26 |
+
interactive: bool = True,
|
27 |
+
visible: bool = True,
|
28 |
+
elem_classes: Optional[str] = "files-container",
|
29 |
+
) -> gr.File:
|
30 |
+
return gr.File(
|
31 |
+
value=value,
|
32 |
+
file_count=file_count,
|
33 |
+
file_types=file_types,
|
34 |
+
label=label,
|
35 |
+
show_label=show_label,
|
36 |
+
interactive=interactive,
|
37 |
+
visible=visible,
|
38 |
+
elem_classes=elem_classes,
|
39 |
+
)
|
40 |
+
|
41 |
+
|
42 |
+
def video_create_ui(
|
43 |
+
value: Optional[str] = None,
|
44 |
+
label: str = "Video Player",
|
45 |
+
file_name: Optional[str] = None,
|
46 |
+
show_label: bool = True,
|
47 |
+
interactive: bool = False,
|
48 |
+
visible: bool = True,
|
49 |
+
elem_classes: Optional[str] = "files-container",
|
50 |
+
) -> gr.Video:
|
51 |
+
if file_name is not None:
|
52 |
+
label += f" ({file_name})"
|
53 |
+
|
54 |
+
return gr.Video(
|
55 |
+
value=value,
|
56 |
+
label=label,
|
57 |
+
show_label=show_label,
|
58 |
+
interactive=interactive,
|
59 |
+
visible=visible,
|
60 |
+
elem_classes=elem_classes,
|
61 |
+
)
|
62 |
+
|
63 |
+
|
64 |
+
def dataframe(
|
65 |
+
headers: Optional[List] = None,
|
66 |
+
values: Optional[List] = None,
|
67 |
+
height: int = 500,
|
68 |
+
wrap: bool = True,
|
69 |
+
visible: bool = True,
|
70 |
+
) -> gr.Dataframe:
|
71 |
+
if headers is None or values is None:
|
72 |
+
datatype = "str"
|
73 |
+
else:
|
74 |
+
datatype = ["markdown"] * len(headers)
|
75 |
+
|
76 |
+
return gr.Dataframe(
|
77 |
+
value=values,
|
78 |
+
headers=headers,
|
79 |
+
datatype=datatype,
|
80 |
+
height=height,
|
81 |
+
wrap=wrap,
|
82 |
+
visible=visible,
|
83 |
+
)
|
84 |
+
|
85 |
+
|
86 |
+
def button(
|
87 |
+
value: str = "",
|
88 |
+
interactive: bool = True,
|
89 |
+
scale: int = 3,
|
90 |
+
elem_classes: Optional[str] = None,
|
91 |
+
) -> gr.Button:
|
92 |
+
return gr.Button(
|
93 |
+
value=value, interactive=interactive, scale=scale, elem_classes=elem_classes
|
94 |
+
)
|
app/config.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
File: config.py
|
3 |
+
Author: Elena Ryumina and Dmitry Ryumin
|
4 |
+
Description: Configuration module for handling settings.
|
5 |
+
License: MIT License
|
6 |
+
"""
|
7 |
+
|
8 |
+
import toml
|
9 |
+
from typing import Callable, Dict
|
10 |
+
from types import SimpleNamespace
|
11 |
+
|
12 |
+
CONFIG_NAME = "config.toml"
|
13 |
+
|
14 |
+
|
15 |
+
def flatten_dict(prefix: str, d: Dict) -> Dict:
|
16 |
+
result = {}
|
17 |
+
|
18 |
+
for k, v in d.items():
|
19 |
+
result.update(flatten_dict(f"{prefix}{k}_", v) if isinstance(v, dict) else {f"{prefix}{k}": v})
|
20 |
+
|
21 |
+
return result
|
22 |
+
|
23 |
+
|
24 |
+
def load_tab_creators(file_path: str, available_functions: Callable) -> Dict:
|
25 |
+
config = toml.load(file_path)
|
26 |
+
tab_creators_data = config.get("TabCreators", {})
|
27 |
+
|
28 |
+
return {key: available_functions[value] for key, value in tab_creators_data.items()}
|
29 |
+
|
30 |
+
|
31 |
+
def load_config(file_path: str) -> SimpleNamespace:
|
32 |
+
config = toml.load(file_path)
|
33 |
+
config_data = flatten_dict("", config)
|
34 |
+
|
35 |
+
return SimpleNamespace(**config_data)
|
36 |
+
|
37 |
+
|
38 |
+
config_data = load_config(CONFIG_NAME)
|
app/description.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
File: description.py
|
3 |
+
Author: Dmitry Ryumin
|
4 |
+
Description: Project description for the Gradio app.
|
5 |
+
License: MIT License
|
6 |
+
"""
|
7 |
+
|
8 |
+
# Importing necessary components for the Gradio app
|
9 |
+
from app.config import config_data
|
10 |
+
|
11 |
+
DESCRIPTION = f"""\
|
12 |
+
# OCEANAI
|
13 |
+
|
14 |
+
<div class="app-flex-container">
|
15 |
+
<img src="https://img.shields.io/badge/version-v{config_data.AppSettings_APP_VERSION}-rc0" alt="Version">
|
16 |
+
</div>
|
17 |
+
"""
|
app/event_handlers/__init__.py
ADDED
File without changes
|
app/event_handlers/calculate_pt_scores_blocks.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
File: clear_blocks.py
|
3 |
+
Author: Elena Ryumina and Dmitry Ryumin
|
4 |
+
Description: Event handler for clearing Gradio app blocks and components.
|
5 |
+
License: MIT License
|
6 |
+
"""
|
7 |
+
|
8 |
+
import gradio as gr
|
9 |
+
|
10 |
+
# Importing necessary components for the Gradio app
|
11 |
+
from app.oceanai_init import b5
|
12 |
+
from app.config import config_data
|
13 |
+
from app.components import html_message, dataframe
|
14 |
+
|
15 |
+
|
16 |
+
def event_handler_calculate_pt_scores_blocks(files, evt_data: gr.EventData):
|
17 |
+
_ = evt_data.target.__class__.__name__
|
18 |
+
|
19 |
+
out = False
|
20 |
+
b5.get_avt_predictions_gradio(
|
21 |
+
paths=files, url_accuracy="", accuracy=False, lang="en", out=out
|
22 |
+
)
|
23 |
+
|
24 |
+
return (
|
25 |
+
html_message(config_data.InformationMessages_NOTI_VIDEOS, False, False),
|
26 |
+
dataframe(
|
27 |
+
headers=b5.df_files_.columns.tolist(),
|
28 |
+
values=b5.df_files_.values.tolist(),
|
29 |
+
visible=True,
|
30 |
+
),
|
31 |
+
)
|
app/event_handlers/clear_blocks.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
File: clear_blocks.py
|
3 |
+
Author: Elena Ryumina and Dmitry Ryumin
|
4 |
+
Description: Event handler for clearing Gradio app blocks and components.
|
5 |
+
License: MIT License
|
6 |
+
"""
|
7 |
+
|
8 |
+
# Importing necessary components for the Gradio app
|
9 |
+
from app.config import config_data
|
10 |
+
from app.components import (
|
11 |
+
html_message,
|
12 |
+
files_create_ui,
|
13 |
+
video_create_ui,
|
14 |
+
button,
|
15 |
+
dataframe,
|
16 |
+
)
|
17 |
+
|
18 |
+
|
19 |
+
def event_handler_clear_blocks():
|
20 |
+
return (
|
21 |
+
html_message(config_data.InformationMessages_NOTI_VIDEOS, False),
|
22 |
+
files_create_ui(),
|
23 |
+
video_create_ui(),
|
24 |
+
button(
|
25 |
+
config_data.OtherMessages_CALCULATE_PT_SCORES,
|
26 |
+
False,
|
27 |
+
3,
|
28 |
+
"calculate_oceanai",
|
29 |
+
),
|
30 |
+
button(config_data.OtherMessages_CLEAR_APP, False, 1, "clear_oceanai"),
|
31 |
+
dataframe(visible=False),
|
32 |
+
)
|
app/event_handlers/event_handlers.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
File: event_handlers.py
|
3 |
+
Author: Dmitry Ryumin
|
4 |
+
Description: File containing functions for configuring event handlers for Gradio components.
|
5 |
+
License: MIT License
|
6 |
+
"""
|
7 |
+
|
8 |
+
import gradio as gr
|
9 |
+
|
10 |
+
# Importing necessary components for the Gradio app
|
11 |
+
from app.event_handlers.files import (
|
12 |
+
event_handler_files,
|
13 |
+
event_handler_files_select,
|
14 |
+
)
|
15 |
+
from app.event_handlers.clear_blocks import event_handler_clear_blocks
|
16 |
+
from app.event_handlers.calculate_pt_scores_blocks import (
|
17 |
+
event_handler_calculate_pt_scores_blocks,
|
18 |
+
)
|
19 |
+
|
20 |
+
|
21 |
+
def setup_app_event_handlers(
|
22 |
+
notifications, files, video, calculate_pt_scores, clear_app, pt_scores
|
23 |
+
):
|
24 |
+
# Events
|
25 |
+
files.change(
|
26 |
+
event_handler_files,
|
27 |
+
[files],
|
28 |
+
[notifications, video, calculate_pt_scores, clear_app],
|
29 |
+
queue=True,
|
30 |
+
)
|
31 |
+
files.select(
|
32 |
+
event_handler_files_select,
|
33 |
+
[files],
|
34 |
+
[video],
|
35 |
+
queue=True,
|
36 |
+
)
|
37 |
+
gr.on(
|
38 |
+
triggers=[calculate_pt_scores.click],
|
39 |
+
fn=event_handler_calculate_pt_scores_blocks,
|
40 |
+
inputs=[files],
|
41 |
+
outputs=[notifications, pt_scores],
|
42 |
+
queue=True,
|
43 |
+
)
|
44 |
+
clear_app.click(
|
45 |
+
fn=event_handler_clear_blocks,
|
46 |
+
inputs=[],
|
47 |
+
outputs=[
|
48 |
+
notifications,
|
49 |
+
files,
|
50 |
+
video,
|
51 |
+
calculate_pt_scores,
|
52 |
+
clear_app,
|
53 |
+
pt_scores,
|
54 |
+
],
|
55 |
+
queue=True,
|
56 |
+
)
|
app/event_handlers/files.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
File: search.py
|
3 |
+
Author: Dmitry Ryumin
|
4 |
+
Description: Event handler for searching and filtering papers in the Gradio app.
|
5 |
+
License: MIT License
|
6 |
+
"""
|
7 |
+
|
8 |
+
import gradio as gr
|
9 |
+
from pathlib import Path
|
10 |
+
|
11 |
+
# Importing necessary components for the Gradio app
|
12 |
+
from app.config import config_data
|
13 |
+
from app.components import html_message, video_create_ui, button
|
14 |
+
|
15 |
+
|
16 |
+
def event_handler_files(files):
|
17 |
+
if not files:
|
18 |
+
return (
|
19 |
+
html_message(config_data.InformationMessages_NOTI_VIDEOS, False),
|
20 |
+
video_create_ui(),
|
21 |
+
button(
|
22 |
+
config_data.OtherMessages_CALCULATE_PT_SCORES,
|
23 |
+
False,
|
24 |
+
3,
|
25 |
+
"calculate_oceanai",
|
26 |
+
),
|
27 |
+
button(config_data.OtherMessages_CLEAR_APP, False, 1, "clear_oceanai"),
|
28 |
+
)
|
29 |
+
|
30 |
+
return (
|
31 |
+
html_message(config_data.OtherMessages_NOTI_CALCULATE, True),
|
32 |
+
video_create_ui(value=files[0], file_name=Path(files[0]).name),
|
33 |
+
button(
|
34 |
+
config_data.OtherMessages_CALCULATE_PT_SCORES,
|
35 |
+
True,
|
36 |
+
3,
|
37 |
+
"calculate_oceanai",
|
38 |
+
),
|
39 |
+
button(config_data.OtherMessages_CLEAR_APP, True, 1, "clear_oceanai"),
|
40 |
+
)
|
41 |
+
|
42 |
+
|
43 |
+
def event_handler_files_select(files, evt: gr.SelectData):
|
44 |
+
return video_create_ui(value=files[evt.index], file_name=evt.value)
|
app/oceanai_init.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
File: oceanai_init.py
|
3 |
+
Author: Elena Ryumina and Dmitry Ryumin
|
4 |
+
Description: OceanAI initialization.
|
5 |
+
License: MIT License
|
6 |
+
"""
|
7 |
+
|
8 |
+
from oceanai.modules.lab.build import Run
|
9 |
+
|
10 |
+
|
11 |
+
def oceanai_initialization():
|
12 |
+
out = False
|
13 |
+
|
14 |
+
# Создание экземпляра класса
|
15 |
+
_b5 = Run(lang="en", metadata=out)
|
16 |
+
|
17 |
+
# Настройка ядра
|
18 |
+
_b5.path_to_save_ = "./models" # Директория для сохранения файла
|
19 |
+
_b5.chunk_size_ = 2000000 # Размер загрузки файла из сети за 1 шаг
|
20 |
+
|
21 |
+
corpus = "fi"
|
22 |
+
|
23 |
+
# Формирование аудиомоделей
|
24 |
+
_ = _b5.load_audio_model_hc(out=out)
|
25 |
+
_ = _b5.load_audio_model_nn(out=out)
|
26 |
+
|
27 |
+
# Загрузка весов аудиомоделей
|
28 |
+
url = _b5.weights_for_big5_["audio"][corpus]["hc"]["sberdisk"]
|
29 |
+
_ = _b5.load_audio_model_weights_hc(url=url, out=out)
|
30 |
+
|
31 |
+
url = _b5.weights_for_big5_["audio"][corpus]["nn"]["sberdisk"]
|
32 |
+
_ = _b5.load_audio_model_weights_nn(url=url, out=out)
|
33 |
+
|
34 |
+
# Формирование видеомоделей
|
35 |
+
_ = _b5.load_video_model_hc(lang="en", out=out)
|
36 |
+
_ = _b5.load_video_model_deep_fe(out=out)
|
37 |
+
_ = _b5.load_video_model_nn(out=out)
|
38 |
+
|
39 |
+
# Загрузка весов видеомоделей
|
40 |
+
url = _b5.weights_for_big5_["video"][corpus]["hc"]["sberdisk"]
|
41 |
+
_ = _b5.load_video_model_weights_hc(url=url, out=out)
|
42 |
+
|
43 |
+
url = _b5.weights_for_big5_["video"][corpus]["fe"]["sberdisk"]
|
44 |
+
_ = _b5.load_video_model_weights_deep_fe(url=url, out=out)
|
45 |
+
|
46 |
+
url = _b5.weights_for_big5_["video"][corpus]["nn"]["sberdisk"]
|
47 |
+
_ = _b5.load_video_model_weights_nn(url=url, out=out)
|
48 |
+
|
49 |
+
# Загрузка словаря с экспертными признаками (текстовая модальность)
|
50 |
+
_ = _b5.load_text_features(out=out)
|
51 |
+
|
52 |
+
# Формирование текстовых моделей
|
53 |
+
_ = _b5.setup_translation_model() # только для русского языка
|
54 |
+
_ = _b5.setup_bert_encoder(force_reload=False, out=out)
|
55 |
+
_ = _b5.load_text_model_hc(corpus=corpus, out=out)
|
56 |
+
_ = _b5.load_text_model_nn(corpus=corpus, out=out)
|
57 |
+
|
58 |
+
# Загрузка весов текстовых моделей
|
59 |
+
url = _b5.weights_for_big5_["text"][corpus]["hc"]["sberdisk"]
|
60 |
+
_ = _b5.load_text_model_weights_hc(url=url, out=out)
|
61 |
+
|
62 |
+
url = _b5.weights_for_big5_["text"][corpus]["nn"]["sberdisk"]
|
63 |
+
_ = _b5.load_text_model_weights_nn(url=url, out=out)
|
64 |
+
|
65 |
+
# Формирование модели для мультимодального объединения информации
|
66 |
+
_ = _b5.load_avt_model_b5(out=out)
|
67 |
+
|
68 |
+
# Загрузка весов модели для мультимодального объединения информации
|
69 |
+
url = _b5.weights_for_big5_["avt"][corpus]["b5"]["sberdisk"]
|
70 |
+
_ = _b5.load_avt_model_weights_b5(url=url, out=out)
|
71 |
+
|
72 |
+
return _b5
|
73 |
+
|
74 |
+
|
75 |
+
b5 = oceanai_initialization()
|
app/tabs.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
File: tabs.py
|
3 |
+
Author: Elena Ryumina and Dmitry Ryumin
|
4 |
+
Description: Gradio app tabs - Contains the definition of various tabs for the Gradio app interface.
|
5 |
+
License: MIT License
|
6 |
+
"""
|
7 |
+
|
8 |
+
import gradio as gr
|
9 |
+
|
10 |
+
# Importing necessary components for the Gradio app
|
11 |
+
from app.description import DESCRIPTION
|
12 |
+
from app.authors import AUTHORS
|
13 |
+
from app.config import config_data
|
14 |
+
from app.components import (
|
15 |
+
html_message,
|
16 |
+
files_create_ui,
|
17 |
+
video_create_ui,
|
18 |
+
button,
|
19 |
+
dataframe,
|
20 |
+
)
|
21 |
+
|
22 |
+
|
23 |
+
def app_tab():
|
24 |
+
gr.Markdown(value=DESCRIPTION)
|
25 |
+
|
26 |
+
with gr.Row():
|
27 |
+
files = files_create_ui()
|
28 |
+
|
29 |
+
video = video_create_ui()
|
30 |
+
|
31 |
+
with gr.Row():
|
32 |
+
calculate_pt_scores = button(
|
33 |
+
config_data.OtherMessages_CALCULATE_PT_SCORES,
|
34 |
+
False,
|
35 |
+
3,
|
36 |
+
"calculate_oceanai",
|
37 |
+
)
|
38 |
+
clear_app = button(
|
39 |
+
config_data.OtherMessages_CLEAR_APP, False, 1, "clear_oceanai"
|
40 |
+
)
|
41 |
+
|
42 |
+
notifications = html_message(config_data.InformationMessages_NOTI_VIDEOS, False)
|
43 |
+
|
44 |
+
pt_scores = dataframe(visible=False)
|
45 |
+
|
46 |
+
return (notifications, files, video, calculate_pt_scores, clear_app, pt_scores)
|
47 |
+
|
48 |
+
|
49 |
+
def about_authors_tab():
|
50 |
+
return gr.Markdown(value=AUTHORS)
|
config.toml
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[AppSettings]
|
2 |
+
APP_VERSION = "0.1.0"
|
3 |
+
CSS_PATH = "app.css"
|
4 |
+
|
5 |
+
[InformationMessages]
|
6 |
+
NOTI_VIDEOS = "Select the video(s)"
|
7 |
+
|
8 |
+
[OtherMessages]
|
9 |
+
CALCULATE_PT_SCORES = "Calculation of Big Five personality traits scores"
|
10 |
+
CLEAR_APP = "Clear"
|
11 |
+
NOTI_CALCULATE = "You can calculate Big Five personality traits scores"
|
12 |
+
|
13 |
+
[TabCreators]
|
14 |
+
"App" = "app_tab"
|
15 |
+
"About the Authors" = "about_authors_tab"
|
16 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio==4.23.0
|
2 |
+
requests==2.31.0
|
3 |
+
PyYAML==6.0.1
|
4 |
+
toml==0.10.2
|
5 |
+
oceanai==1.0.0a21
|