Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PMI discussion #618

Open
wants to merge 742 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
742 commits
Select commit Hold shift + click to select a range
db2ea56
emotion detection videofile support added
moon-strider Sep 22, 2023
b3ca3a4
minor refactoring
moon-strider Sep 26, 2023
e46eb78
minor refactoring
moon-strider Sep 26, 2023
4219a17
style fix
moon-strider Sep 26, 2023
f7472b8
style fix
moon-strider Sep 26, 2023
2428782
more pr fixes, more style fixed
moon-strider Sep 26, 2023
7f0ce75
more pr fixes, more style fixed
moon-strider Sep 26, 2023
d1dff5f
even more pr fixes
moon-strider Sep 26, 2023
cb25e05
even more pr fixes
moon-strider Sep 26, 2023
1fddb31
argument dockerfile fixes
moon-strider Sep 26, 2023
2e7d957
argument dockerfile fixes
moon-strider Sep 26, 2023
289cd89
Dockerfile fix
moon-strider Sep 26, 2023
4ba2bf4
Dockerfile fix
moon-strider Sep 26, 2023
6afc7dc
updating dp-agent commit
moon-strider Sep 26, 2023
d78c120
updating dp-agent commit
moon-strider Sep 26, 2023
a297142
adding file server to dream_ocean dist
moon-strider Sep 26, 2023
efd5e9c
adding file server to dream_ocean dist
moon-strider Sep 26, 2023
dbead47
more pr fixes
moon-strider Sep 26, 2023
baf9d97
more pr fixes
moon-strider Sep 26, 2023
f971885
fixed a critical typo in dockerfile
moon-strider Sep 26, 2023
2818e8f
fixed a critical typo in dockerfile
moon-strider Sep 26, 2023
8981183
ignoring E402 for some lines of code
moon-strider Sep 27, 2023
0d06b22
ignoring E402 for some lines of code
moon-strider Sep 27, 2023
a822ca1
attempting to fix E402
moon-strider Sep 27, 2023
e098a14
attempting to fix E402
moon-strider Sep 27, 2023
9678e7e
another attempt at fixing E402
moon-strider Sep 27, 2023
71d5a94
another attempt at fixing E402
moon-strider Sep 27, 2023
54d99c9
another one
moon-strider Sep 27, 2023
da30757
another one
moon-strider Sep 27, 2023
2700bae
Fix/use gen configs in chatcompletion (#573)
dilyararimovna Sep 28, 2023
0b4223d
fix: werkzeug error (#574)
IgnatovFedor Oct 2, 2023
5979493
Ru mtl (#566)
dimakarp1996 Oct 10, 2023
dc75ba5
Refactoring skills display name (#578)
RafilGalimzyanov Oct 11, 2023
e6031f4
fixing path to chatgpt skill configurations (#580)
RafilGalimzyanov Oct 17, 2023
67415ff
updates to dream_kg distribution (#581)
annakorz Oct 24, 2023
8478b01
Feat/pytest tests (#548)
NeoIsALie Oct 24, 2023
d74a815
Modify davinci config so it works better in russian (#587)
RafilGalimzyanov Nov 7, 2023
402e5d7
fix: response selectors tags (#588)
dilyararimovna Nov 7, 2023
52ea8f5
feat: dream russian persona based (#590)
dilyararimovna Nov 11, 2023
38e5dd3
update property extraction (#576)
zucchini-nlp Nov 13, 2023
fd75515
update OpenAI version to 1.2.3 (#592)
RafilGalimzyanov Nov 13, 2023
f605640
Dream emotion dist (#568)
asleepann Nov 16, 2023
f3cb2c7
Feat/update openai (#593)
dilyararimovna Nov 18, 2023
1f307c8
Dream_kg_prompted distribution (#567)
Ramimashkouk Nov 21, 2023
7607c75
feat: add mistral 7b 128k (#589)
dilyararimovna Nov 22, 2023
867c8e4
fix: user-km and skill tests for dream_kg (#595)
annakorz Nov 28, 2023
22bbbfa
feat: add system requirements (#599)
dilyararimovna Dec 3, 2023
2d6a873
Add configs for gpt4-turbo (#598)
RafilGalimzyanov Dec 3, 2023
72d90a8
Add configs to envvars_to_send
RafilGalimzyanov Dec 4, 2023
b50b055
Merge pull request #600 from deeppavlov/fix/envvars-to-send
RafilGalimzyanov Dec 4, 2023
66f57ac
User km updates (#597)
annakorz Dec 5, 2023
a76e882
Feat/dff/voice skill (#362)
moon-strider Dec 6, 2023
3c78931
[WIP] component readme updates (#536)
nstsj Dec 11, 2023
9273f91
Dream kg prompted port fix (#601)
annakorz Dec 11, 2023
348395b
new models added
Dec 11, 2023
8317da0
new models added
Dec 11, 2023
3ccd51e
Merge remote-tracking branch 'origin/dev' into feat/emotions
Dec 12, 2023
3fc8eb4
Merge remote-tracking branch 'origin/dev' into feat/emotions
Dec 12, 2023
787ed66
Bot kg annotator (#586)
annakorz Dec 12, 2023
0d11584
minor changes
Dec 13, 2023
7a85a5d
minor changes
Dec 13, 2023
cbf4d37
fromage image skill fixed (#603)
moon-strider Dec 14, 2023
93a4947
formatters slightly changed
Dec 14, 2023
e286994
formatters slightly changed
Dec 14, 2023
ba19cf7
dp_formatter for emotion-detection and personality-detection + review…
Dec 22, 2023
79d545f
dp_formatter for emotion-detection and personality-detection + review…
Dec 22, 2023
9caeefb
nano error fixed
Dec 22, 2023
c17fab8
nano error fixed
Dec 22, 2023
58e5e31
port changed, redundant features file added to docker
Dec 26, 2023
c17229c
port changed, redundant features file added to docker
Dec 26, 2023
d8ecfb7
port fixed(2)
Dec 26, 2023
5aa4adc
port fixed(2)
Dec 26, 2023
437a551
port fixed(3)
Dec 26, 2023
0933f23
port fixed(3)
Dec 26, 2023
9a41e4c
Merge branch 'dev' into feat/emotions
rock-n-shrimproll Dec 26, 2023
5e4c49f
Merge branch 'dev' into feat/emotions
rock-n-shrimproll Dec 26, 2023
5347bc5
codestyle fixed
Dec 26, 2023
448e531
codestyle fixed
Dec 26, 2023
70b2088
Merge branch 'feat/emotions' of https://github.com/deeppavlov/dream i…
Dec 26, 2023
8d6daa7
Merge branch 'feat/emotions' of https://github.com/deeppavlov/dream i…
Dec 26, 2023
9150b11
codestyle fixed 2
Dec 26, 2023
afd7578
codestyle fixed 2
Dec 26, 2023
890d7f8
personality-detection models added
Dec 27, 2023
73d4462
personality-detection models added
Dec 27, 2023
db14239
minor changes
Dec 27, 2023
3a88b3f
minor changes
Dec 27, 2023
9c2d20c
personality detection models added to files.deeppavlov
Dec 29, 2023
5c5e725
personality detection models added to files.deeppavlov
Dec 29, 2023
bbe438b
gdown -> wget from files
moon-strider Jan 15, 2024
0680d8f
gdown -> wget from files
moon-strider Jan 15, 2024
e5fc23e
emotion detection files fixed
Jan 15, 2024
26023df
emotion detection files fixed
Jan 15, 2024
fec171b
fix: tests
dilyararimovna Jan 15, 2024
329323f
fix: tests
dilyararimovna Jan 15, 2024
f053a18
lost file added
Jan 16, 2024
3bb4224
lost file added
Jan 16, 2024
5f3dfdb
feat: use dream persona in dream ocean
dilyararimovna Jan 16, 2024
c490a6b
feat: use dream persona in dream ocean
dilyararimovna Jan 16, 2024
7975105
vidchapters added
Apr 2, 2024
7e9610d
vidchapters added
Apr 2, 2024
ee6160e
Skill created
Apr 9, 2024
eedf05f
Skill created
Apr 9, 2024
b692e8e
dockerfile changed
May 22, 2024
b5bb9cc
dockerfile changed
May 22, 2024
111580c
docker and server edited
May 28, 2024
245cd88
docker and server edited
May 28, 2024
e550a78
remak asr and vid2seq into functions
Jun 17, 2024
a712380
remak asr and vid2seq into functions
Jun 17, 2024
e71d8b7
video captioning service 1st attempt
Jul 3, 2024
19df4e7
video captioning service 1st attempt
Jul 3, 2024
b5ce973
vidchapters service attempt 3
Jul 3, 2024
738df07
vidchapters service attempt 3
Jul 3, 2024
8bae5da
vidchapters service attempt 4
Jul 3, 2024
0b5eee1
vidchapters service attempt 4
Jul 3, 2024
b97f7ac
fix copying problems
oserikov Jul 3, 2024
126da9c
fix copying problems
oserikov Jul 3, 2024
89eb62a
Vidchapters skill remade
Jul 7, 2024
93b1a9a
Vidchapters skill remade
Jul 7, 2024
b607fa4
Formatters changed, service minor changes
Jul 8, 2024
5eca267
Formatters changed, service minor changes
Jul 8, 2024
f54f319
error while downloading whisper
Jul 8, 2024
1a259d3
error while downloading whisper
Jul 8, 2024
aafee32
Major changes to fix ffmpeg and whisper connection
Jul 8, 2024
6cdbeeb
Major changes to fix ffmpeg and whisper connection
Jul 8, 2024
cda23a3
Major changes to fix ffmpeg and whisper connection
Jul 8, 2024
a321c5c
Major changes to fix ffmpeg and whisper connection
Jul 8, 2024
0d80af9
ffmpeg fixed, bvidia drivers for ASR alining model in progress
Jul 8, 2024
6b02767
ffmpeg fixed, bvidia drivers for ASR alining model in progress
Jul 8, 2024
981a004
server rewritten
Jul 25, 2024
43eb911
server rewritten
Jul 25, 2024
34a8e2b
Oleg's help with t5 tokenizer needed
Jul 25, 2024
9e6f498
Oleg's help with t5 tokenizer needed
Jul 25, 2024
585c9c1
cuda added
Jul 26, 2024
79a3015
cuda added
Jul 26, 2024
fb3096d
models ready
Jul 26, 2024
dfe407e
models ready
Jul 26, 2024
c779fb9
Service is ready
Jul 29, 2024
157fed5
Service is ready
Jul 29, 2024
9e7e80e
Tests ready
Aug 29, 2024
db5ca0d
Tests ready
Aug 29, 2024
b0ce82c
tests edited
Sep 24, 2024
49e7bd1
tests edited
Sep 24, 2024
43369a1
Fromage fixed
Sep 29, 2024
6ac4c8b
Fromage fixed
Sep 29, 2024
84ffefa
dialogpt removed
Oct 1, 2024
fa6a1e7
dialogpt removed
Oct 1, 2024
d35fe3e
Tests for voice_service & fromage
Oct 11, 2024
7fbba0f
Tests for voice_service & fromage
Oct 11, 2024
6d04bab
Separated into dream_multimodal and dream_voice
Oct 22, 2024
9e0e78e
Separated into dream_multimodal and dream_voice
Oct 22, 2024
c988179
Test remastered
Oct 25, 2024
232c7d7
Test remastered
Oct 25, 2024
a4d86c9
Tests super remastered
Oct 25, 2024
471579e
Tests super remastered
Oct 25, 2024
a0c64f6
voice_service fixes
rock-n-shrimproll Oct 27, 2024
4997720
voice_service fixes
rock-n-shrimproll Oct 27, 2024
e928832
fix wrong model file was used
oserikov Oct 27, 2024
f554728
fix wrong model file was used
oserikov Oct 27, 2024
6eb1a49
upd tests
oserikov Oct 27, 2024
4e5e774
upd tests
oserikov Oct 27, 2024
1cb3702
wip fixes
oserikov Oct 27, 2024
84b0961
wip fixes
oserikov Oct 27, 2024
330fff5
wip fixes
oserikov Oct 27, 2024
5da30a1
wip fixes
oserikov Oct 27, 2024
07b6274
fix file paths
oserikov Nov 6, 2024
0de1160
fix file paths
oserikov Nov 6, 2024
6e70e0f
added german_translation_pa
moon-strider Nov 6, 2024
e2f1622
added german_translation_pa
moon-strider Nov 6, 2024
49fafc6
added configs for german_translation_pa annotator into dream_multimodal
moon-strider Nov 6, 2024
c342e48
added configs for german_translation_pa annotator into dream_multimodal
moon-strider Nov 6, 2024
9937083
fixed compose file for dream_multimodal to include new annotator
moon-strider Nov 6, 2024
8481ca9
fixed compose file for dream_multimodal to include new annotator
moon-strider Nov 6, 2024
275b655
added env checks, added gigachat api service to multimodal compose
moon-strider Nov 6, 2024
1049008
added env checks, added gigachat api service to multimodal compose
moon-strider Nov 6, 2024
f92d404
added german_translation_pa to dream_voice
moon-strider Nov 6, 2024
946df94
added german_translation_pa to dream_voice
moon-strider Nov 6, 2024
2eb7eec
updated pydantic model for german_translator_pa
moon-strider Nov 6, 2024
650226a
updated pydantic model for german_translator_pa
moon-strider Nov 6, 2024
ccd29c0
fromage model changed
rock-n-shrimproll Nov 6, 2024
3bcc4a6
fromage model changed
rock-n-shrimproll Nov 6, 2024
0fbd45d
fromage model changed
rock-n-shrimproll Nov 6, 2024
f92ab8e
fromage model changed
rock-n-shrimproll Nov 6, 2024
45d2e88
Merge branch 'feat/dff/vidchapters' of https://github.com/deeppavlov/…
rock-n-shrimproll Nov 6, 2024
f9d810e
Merge branch 'feat/dff/vidchapters' of https://github.com/deeppavlov/…
rock-n-shrimproll Nov 6, 2024
457340e
german translation pa added to dream_voice and dream_multimodal (work…
moon-strider Nov 6, 2024
36dfd14
german translation pa added to dream_voice and dream_multimodal (work…
moon-strider Nov 6, 2024
e528901
fromage bleu ready
rock-n-shrimproll Nov 8, 2024
3ea95f1
fromage bleu ready
rock-n-shrimproll Nov 8, 2024
9041367
Add async
anna-a-m Nov 11, 2024
087c966
Add async
anna-a-m Nov 11, 2024
75088f3
Add async
anna-a-m Nov 11, 2024
507ce3d
Add async
anna-a-m Nov 11, 2024
c33270f
Add async
anna-a-m Nov 11, 2024
8cee4bd
Add async
anna-a-m Nov 11, 2024
b5cf5d6
Add async
anna-a-m Nov 11, 2024
3901a6c
Add async
anna-a-m Nov 11, 2024
2b54f6b
Add async
anna-a-m Nov 11, 2024
1d46bf2
Add async
anna-a-m Nov 11, 2024
667fbfd
Voice service bleu metrics ready
rock-n-shrimproll Nov 12, 2024
06e62d7
Voice service bleu metrics ready
rock-n-shrimproll Nov 12, 2024
e536ad7
Voice-service bleu metrics ready
rock-n-shrimproll Nov 12, 2024
92c9f37
Voice-service bleu metrics ready
rock-n-shrimproll Nov 12, 2024
af8f7e3
Added fromage_with_predictions.csv
rock-n-shrimproll Nov 12, 2024
c348341
Added fromage_with_predictions.csv
rock-n-shrimproll Nov 12, 2024
f4e8cb1
Merge branch 'feat/dff/vidchapters' of https://github.com/deeppavlov/…
rock-n-shrimproll Nov 12, 2024
a3dc1a2
Merge branch 'feat/dff/vidchapters' of https://github.com/deeppavlov/…
rock-n-shrimproll Nov 12, 2024
276529b
merge errors fixed
rock-n-shrimproll Nov 12, 2024
223e1a3
merge errors fixed
rock-n-shrimproll Nov 12, 2024
7a60f3b
Tests fixed
rock-n-shrimproll Nov 13, 2024
b95c20a
Tests fixed
rock-n-shrimproll Nov 13, 2024
b5079a9
Add async
anna-a-m Nov 14, 2024
3f6cacb
Add async
anna-a-m Nov 14, 2024
8f31135
Add async
anna-a-m Nov 14, 2024
aa4281f
Add async
anna-a-m Nov 14, 2024
c6d66f5
Add async
anna-a-m Nov 14, 2024
450f9a1
Add async
anna-a-m Nov 14, 2024
8ff34f4
Add async
anna-a-m Nov 14, 2024
b7c30b8
Add async
anna-a-m Nov 14, 2024
519b086
Add async
anna-a-m Nov 14, 2024
c0a0741
Add async
anna-a-m Nov 14, 2024
3b9927e
Add async
anna-a-m Nov 14, 2024
72a4051
Add async
anna-a-m Nov 14, 2024
0be2a7e
Add async
anna-a-m Nov 14, 2024
2d622ca
Add async
anna-a-m Nov 14, 2024
d199bbb
Add async
anna-a-m Nov 14, 2024
76f9202
Add async
anna-a-m Nov 14, 2024
76e65db
Add async
anna-a-m Nov 14, 2024
ae984ec
Add async
anna-a-m Nov 14, 2024
9adaeb3
readme ready
rock-n-shrimproll Nov 15, 2024
b7a5816
readme ready
rock-n-shrimproll Nov 15, 2024
c93b06f
Try 2 endpoints async solution
anna-a-m Nov 15, 2024
9c1cc80
Try 2 endpoints async solution
anna-a-m Nov 15, 2024
f8e3dad
updated voice service and voice skill for task scheduling
moon-strider Nov 19, 2024
2c0f8bf
updated voice service and voice skill for task scheduling
moon-strider Nov 19, 2024
6a641d0
first test in voice almost fixed
rock-n-shrimproll Nov 20, 2024
f3a5b99
first test in voice almost fixed
rock-n-shrimproll Nov 20, 2024
82d43fc
fromage parallel requests fixed
moon-strider Nov 20, 2024
1ceaed0
fromage parallel requests fixed
moon-strider Nov 20, 2024
7d8387e
vidchapters fixed for parallel requests
moon-strider Nov 20, 2024
bef6411
vidchapters fixed for parallel requests
moon-strider Nov 20, 2024
c7c71ca
voice service tests totally fixed
rock-n-shrimproll Nov 20, 2024
274638e
voice service tests totally fixed
rock-n-shrimproll Nov 20, 2024
699192c
fromage tests totally fixed
rock-n-shrimproll Nov 20, 2024
7a34ff4
fromage tests totally fixed
rock-n-shrimproll Nov 20, 2024
20bcae9
vidchapters tests fixed
rock-n-shrimproll Nov 20, 2024
0391957
vidchapters tests fixed
rock-n-shrimproll Nov 20, 2024
b990d7b
fromage json problem fixed
rock-n-shrimproll Nov 21, 2024
84411b7
Merge branch 'feat/dff/vidchapters' of https://github.com/deeppavlov/…
rock-n-shrimproll Nov 21, 2024
f00b5ba
try to fix commits
rock-n-shrimproll Nov 22, 2024
3055ee6
ports for dream_voice fixed
rock-n-shrimproll Nov 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions annotators/emotion_detection/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM nvidia/cuda:12.1.1-base-ubuntu20.04

RUN apt update
RUN apt install -y python3.9
RUN apt install -y git python3-pip

ARG VIDEO_PRETRAINED
ARG TEXT_PRETRAINED
ARG MODEL_PATH
ARG MULTIMODAL_MODEL
ARG REDUNDANT_FEATURES

ENV VIDEO_PRETRAINED=$VIDEO_PRETRAINED
ENV TEXT_PRETRAINED=$TEXT_PRETRAINED
ENV MULTIMODAL_MODEL=$MULTIMODAL_MODEL
ENV MODEL_PATH=$MODEL_PATH
ENV REDUNDANT_FEATURES=$REDUNDANT_FEATURES

WORKDIR /src

COPY . /src
RUN mkdir /data
RUN pip install -r requirements.txt

RUN apt install -y ffmpeg=7:4.2.7-0ubuntu0.1 libsm6=2:1.2.3-1 libxext6=2:1.3.4-0ubuntu1

RUN pip install gdown==4.7.1

RUN git clone https://github.com/anna-a-m/MultimodalERC /data/repo && cd /data/repo && git reset --hard 84097d442b23b5a9238b5090a04e2625741314ae

RUN mv -f /data/repo/* /data/ && rm -rf /data/repo

RUN touch /data/multimodal_concat/__init__.py

RUN apt-get install -y wget

RUN wget -O models http://files.deeppavlov.ai/dream_data/emotion_detection/emotion_detection_v1.tar.gz && tar -xf models -C /data/
RUN wget -O redundant_feat http://files.deeppavlov.ai/dream_data/emotion_detection/redundant_feat.txt && mv -f redundant_feat /data/
4 changes: 4 additions & 0 deletions annotators/emotion_detection/aux.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import sys

sys.path.append("/data")
sys.path.append("/data/multimodal_concat")
16 changes: 16 additions & 0 deletions annotators/emotion_detection/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
pandas==1.5.3
scikit-learn==1.3.0
tqdm==4.64.1
opencv-python==4.7.0.68
opensmile==2.4.2
sentry-sdk==1.15.0
torch==1.13.1
transformers==4.31.0
fastapi==0.103.0
blinker==1.5.0
pydantic==2.3.0
numpy==1.24.4
starlette==0.27.0
uvicorn==0.23.2
Pillow==9.3.0
wandb==0.13.9
199 changes: 199 additions & 0 deletions annotators/emotion_detection/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
import logging
import os
import opensmile
import torch
import numpy as np
import sentry_sdk
import cv2
import aux # noqa: F401

from multimodal_concat.models import MultimodalClassificationModel, MainModel
from multimodal_concat.utils import prepare_models

from fastapi import FastAPI
from fastapi.encoders import jsonable_encoder
from pydantic import BaseModel
from starlette.middleware.cors import CORSMiddleware
from transformers import AutoTokenizer, AutoProcessor
from typing import List
from urllib.request import urlretrieve

sentry_sdk.init(dsn=os.getenv("SENTRY_DSN"))

label2id = {
"anger": 0,
"disgust": 1,
"fear": 2,
"joy": 3,
"neutral": 4,
"sadness": 5,
"surprise": 6,
}
num_labels = 7
text_model, video_model, audio_model = prepare_models(num_labels, os.getenv("MODEL_PATH"))

logger = logging.getLogger(__name__)


def sample_frame_indices(seg_len, clip_len=16, frame_sample_rate=4, mode="video"):
converted_len = int(clip_len * frame_sample_rate)
converted_len = min(converted_len, seg_len - 1)
end_idx = np.random.randint(converted_len, seg_len)
start_idx = end_idx - converted_len
if mode == "video":
indices = np.linspace(start_idx, end_idx, num=clip_len)
else:
indices = np.linspace(start_idx, end_idx, num=clip_len * frame_sample_rate)
indices = np.clip(indices, start_idx, end_idx - 1).astype(np.int64)
return indices


def get_frames(
file_path,
clip_len=16,
):
cap = cv2.VideoCapture(file_path)
v_len = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
indices = sample_frame_indices(v_len)

frames = []
for fn in range(v_len):
success, frame = cap.read()
if success is False:
continue
if fn in indices:
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
res = cv2.resize(frame, dsize=(224, 224), interpolation=cv2.INTER_CUBIC)
frames.append(res)
cap.release()

if len(frames) < clip_len:
add_num = clip_len - len(frames)
frames_to_add = [frames[-1]] * add_num
frames.extend(frames_to_add)

return frames


def create_final_model():
multi_model = MultimodalClassificationModel(
text_model,
video_model,
audio_model,
num_labels,
input_size=4885,
hidden_size=512,
)
checkpoint = torch.load(os.getenv("MULTIMODAL_MODEL"))
multi_model.load_state_dict(checkpoint)

device = "cuda"
return MainModel(multi_model, device=device)


def process_text(input_tokens: str):
text_model_name = os.getenv("TEXT_PRETRAINED")
logger.info(f"{text_model_name}")
tokenizer = AutoTokenizer.from_pretrained(text_model_name)

return tokenizer(
input_tokens,
padding="max_length",
truncation=True,
max_length=128,
return_tensors="pt",
)


def process_video(video_path: str):
video_frames = get_frames(video_path)

video_model_name = os.getenv("VIDEO_PRETRAINED")
video_feature_extractor = AutoProcessor.from_pretrained(video_model_name)

return video_feature_extractor(videos=video_frames, return_tensors="pt")


def process_audio(file_path: str):
smile = opensmile.Smile(
opensmile.FeatureSet.ComParE_2016,
opensmile.FeatureLevel.Functionals,
sampling_rate=16000,
resample=True,
num_workers=5,
verbose=True,
)

redundant_features = os.getenv("REDUNDANT_FEATURES")
with open(redundant_features, "r") as features_file:
redundant_features_list = features_file.read().split(",")

audio_features = smile.process_files([file_path])
audio_features = audio_features.drop(columns=redundant_features_list, inplace=False)
return audio_features.values.reshape(audio_features.shape[0], 1, audio_features.shape[1])


def inference(text: str, video_path: str):
text_encoding = process_text(text)
video_encoding = process_video(video_path)
audio_features = process_audio(video_path)
batch = {
"text": text_encoding,
"video": video_encoding,
"audio": audio_features,
"label": None,
}
label = final_model(batch)
id2label = {v: k for k, v in label2id.items()}
return id2label[int(label.detach().cpu())]


def predict_emotion(text: str, video_path: str):
try:
logger.warning(f"{inference(text, video_path)}")
return inference(text, video_path)
except Exception as e:
sentry_sdk.capture_exception(e)
raise e


final_model = create_final_model()


class EmotionsPayload(BaseModel):
personality: List[str]
video_path: List[str]


def subinfer(msg_text: str, video_path: str):
emotion = "Emotion detection unsuccessfull. An error occured during inference."
filepath = "undefined"
try:
filename = video_path.split("=")[-1]
filepath = f"/data/{filename}"
urlretrieve(video_path, filepath)
if not os.path.exists(filepath):
raise ValueError(f"Failed to retrieve videofile from {filepath}")
emotion = predict_emotion(msg_text + " ", filepath)
logger.info(f"Detected emotion: {jsonable_encoder(emotion)}")
except Exception as e:
raise ValueError(f"The message format is correct, but: {e}")

return emotion


app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)


@app.post("/model")
def infer(payload: EmotionsPayload):
logger.info(f"Emotion Detection: {payload}")
emotion = [subinfer(p[0], p[1]) for p in zip(payload.personality, payload.video_path)]
return jsonable_encoder(emotion)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
SERVICE_PORT: 8040
SERVICE_NAME: emotion_detection
CUDA_VISIBLE_DEVICES: 0
VIDEO_PRETRAINED: "microsoft/xclip-base-patch32"
EXT_PRETRAINED: "bert-large-uncased"
MULTIMODAL_MODEL: "final_model.pt"
REDUNDANT_FEATURES: "redundant_features.txt"
MODEL_PATH: "/data/"
PREFIX: "Detect emotions:"
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: emotion-detection
endpoints:
- model
compose:
env_file:
- .env
build:
args:
SERVICE_PORT: 8040
SERVICE_NAME: emotion_detection
VIDEO_PRETRAINED: "microsoft/xclip-base-patch32"
TEXT_PRETRAINED: "bert-large-uncased"
MULTIMODAL_MODEL: "final_model.pt"
REDUNDANT_FEATURES: "redundant_features.txt"
MODEL_PATH: "/data/"
PREFIX: "Detect emotions:"
context: .
dockerfile: ./annotators/emotion_detection/Dockerfile
command: uvicorn server:app --host 0.0.0.0 --port 8040
deploy:
resources:
limits:
memory: 1G
reservations:
memory: 1G
environment:
- CUDA_VISIBLE_DEVICES=0
ports:
- 8040:8040
13 changes: 13 additions & 0 deletions annotators/german_translation_pa/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM python:3.9-slim

WORKDIR /app

COPY requirements.txt .

RUN pip install --no-cache-dir -r requirements.txt

COPY . .

EXPOSE 8181

CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8181"]
5 changes: 5 additions & 0 deletions annotators/german_translation_pa/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fastapi==0.95.2
uvicorn==0.22.0
requests==2.31.0
pydantic==1.10.12
gigachat==0.1.35
55 changes: 55 additions & 0 deletions annotators/german_translation_pa/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import os
import logging
from typing import List

from fastapi import FastAPI, HTTPException
from fastapi.encoders import jsonable_encoder
from pydantic import BaseModel

from gigachat import GigaChat
from gigachat.models import Chat

app = FastAPI()

class TextInput(BaseModel):
sentences: List[str]

if not all([os.getenv("GIGACHAT_CREDENTIAL"), os.getenv("GIGACHAT_SCOPE")]):
logging.error("ENV VARIABLES FOR GIGACHAT ARE NOT SET, THE SERVICE WILL NOT WORK")

@app.post("/translate")
def translate_text(payload: TextInput):
gigachat_api_key = os.getenv("GIGACHAT_CREDENTIAL")
gigachat_org = os.getenv("GIGACHAT_SCOPE")

if not all([gigachat_api_key, gigachat_org]):
logging.error("Gigachat credentials are not set")
raise HTTPException(status_code=500, detail="Gigachat credentials are not set")

translated_text = []

for msg in payload.sentences:
try:
giga = GigaChat(credentials=gigachat_api_key, verify_ssl_certs=False)

messages = [
{
"role": "system",
"content": "You are a translator that translates English text into German."
},
{
"role": "user",
"content": msg
}
]

payload = Chat(messages=messages, scope=gigachat_org)

response = giga.chat(payload)

translated_text += [response.choices[0].message.content.strip()]
logging.info(f"Translated text: {translated_text}")
except Exception as e:
logging.exception("Error during translation")
raise HTTPException(status_code=500, detail=str(e))
return jsonable_encoder([{"batch": translated_text}])
2 changes: 1 addition & 1 deletion annotators/kbqa/tests/test_kbqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
),
(
{"x_init": ["How old is Donald Trump?"], "entities": [["Donald Trump"]], "entity_tags": [[["per", 1.0]]]},
"Donald Trump is 77 years old.",
"Donald Trump is 78 years old.",
),
],
)
Expand Down
Loading