-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from meedan/cv2-3435-add-presto-to-alegre
CV2-3435 minor tweaks as per alegre audio replacement work
- Loading branch information
Showing
12 changed files
with
69 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,60 @@ | ||
from typing import Any, List, Union | ||
from pydantic import BaseModel, HttpUrl | ||
from typing import Any, List, Optional, Union | ||
from pydantic import BaseModel | ||
|
||
# Output hash values can be of different types. | ||
HashValue = Union[List[float], str, int] | ||
class TextInput(BaseModel): | ||
id: str | ||
callback_url: HttpUrl | ||
callback_url: str | ||
text: str | ||
|
||
class TextOutput(BaseModel): | ||
id: str | ||
callback_url: HttpUrl | ||
callback_url: str | ||
text: str | ||
|
||
class VideoInput(BaseModel): | ||
id: str | ||
callback_url: HttpUrl | ||
url: HttpUrl | ||
callback_url: str | ||
url: str | ||
|
||
class VideoOutput(BaseModel): | ||
id: str | ||
callback_url: HttpUrl | ||
url: HttpUrl | ||
callback_url: str | ||
url: str | ||
bucket: str | ||
outfile: str | ||
hash_value: HashValue | ||
|
||
class AudioInput(BaseModel): | ||
id: str | ||
callback_url: HttpUrl | ||
url: HttpUrl | ||
callback_url: str | ||
url: str | ||
|
||
class AudioOutput(BaseModel): | ||
id: str | ||
callback_url: HttpUrl | ||
url: HttpUrl | ||
callback_url: str | ||
url: str | ||
hash_value: HashValue | ||
|
||
class ImageInput(BaseModel): | ||
id: str | ||
callback_url: HttpUrl | ||
url: HttpUrl | ||
callback_url: str | ||
url: str | ||
|
||
class ImageOutput(BaseModel): | ||
id: str | ||
callback_url: HttpUrl | ||
url: HttpUrl | ||
callback_url: str | ||
url: str | ||
hash_value: HashValue | ||
|
||
class GenericInput(BaseModel): | ||
id: str | ||
callback_url: str | ||
url: Optional[str] = None | ||
text: Optional[str] = None | ||
raw: Optional[dict] = {} | ||
|
||
class Message(BaseModel): | ||
body: Union[TextInput, VideoInput, AudioInput, ImageInput] | ||
body: GenericInput | ||
response: Any |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import os | ||
import sentry_sdk | ||
from lib.helpers import get_environment_setting | ||
|
||
sentry_sdk.init( | ||
dsn=get_environment_setting('sentry_sdk_dsn'), | ||
environment=get_environment_setting("DEPLOY_ENV"), | ||
traces_sample_rate=1.0, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,27 @@ | ||
import os | ||
import unittest | ||
from unittest.mock import MagicMock | ||
|
||
import numpy as np | ||
|
||
from unittest.mock import patch, MagicMock | ||
from lib.model.fasttext import FasttextModel | ||
from lib import schemas | ||
|
||
class TestFasttextModel(unittest.TestCase): | ||
def setUp(self): | ||
self.model = FasttextModel() | ||
self.mock_model = MagicMock() | ||
|
||
def test_respond(self): | ||
@patch('lib.model.fasttext.hf_hub_download') | ||
@patch('lib.model.fasttext.fasttext.load_model') | ||
def test_respond(self, mock_fasttext_load_model, mock_hf_hub_download): | ||
mock_hf_hub_download.return_value = 'mocked_path' | ||
mock_fasttext_load_model.return_value = self.mock_model | ||
self.mock_model.predict.return_value = (['__label__eng_Latn'], [0.9]) | ||
|
||
model = FasttextModel() # Now it uses mocked functions | ||
query = [schemas.Message(body=schemas.TextInput(id="123", callback_url="http://example.com/callback", text="Hello, how are you?")), schemas.Message(body=schemas.TextInput(id="123", callback_url="http://example.com/callback", text="今天是星期二"))] | ||
|
||
response = self.model.respond(query) | ||
response = model.respond(query) | ||
|
||
self.assertEqual(len(response), 2) | ||
self.assertEqual(response[0].response, "__label__eng_Latn") | ||
self.assertEqual(response[1].response, "__label__zho_Hans") | ||
self.assertEqual(response[0].response, '__label__eng_Latn') | ||
self.assertEqual(response[1].response, '__label__eng_Latn') # Mocked, so it will be the same | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters