Skip to content

Commit

Permalink
Merge branch 'master' into org-support
Browse files Browse the repository at this point in the history
  • Loading branch information
nikochiko authored Aug 19, 2024
2 parents 4eb04d3 + 1119c84 commit 0ebcc56
Show file tree
Hide file tree
Showing 37 changed files with 372 additions and 153 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/gitleaks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: gitleaks
on: [pull_request, push, workflow_dispatch]
jobs:
scan:
name: gitleaks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE}}
GITLEAKS_NOTIFY_USER_LIST: '@sandergi'
21 changes: 21 additions & 0 deletions .gitleaksignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
4749e3ef005e8ddc6562d1bd82a00e752a7e94e3:explore.py:aws-access-token:16
4749e3ef005e8ddc6562d1bd82a00e752a7e94e3:explore.py:private-key:23
4749e3ef005e8ddc6562d1bd82a00e752a7e94e3:explore.py:generic-api-key:32
b0c80dac8e22faafa319d5466947df8723dfaa4a:daras_ai_v2/img_model_settings_widgets.py:generic-api-key:372
8670036e722f40530dbff3e0e7573e9b5aac85c9:routers/slack.py:slack-webhook-url:73
b6ad1fc0168832711adcff07287907660f3305fb:bots/location.py:generic-api-key:12
8c05ec8320a866304842fb5f4df76e0698f1031f:bots/analysis.py:generic-api-key:5
1c03d569dd30bb9703e4ff968a57a05eb405e398:bots/signals.py:generic-api-key:11
5e3dd6cf0da20b3e5b1daaca41ad126bc489fbf3:static/js/auth.js:generic-api-key:2
87e443addbbc49746ab3088307a59b3e2fc2d177:recipes/CompareText2Img.py:generic-api-key:97
1f109a743b1781c7a21c1b0ca6a3f880f7f7dc84:recipes/CompareText2Img.py:generic-api-key:77
d18d8b9bb18a9ff8248b16b26f0455f7826ce23a:recipes/CompareText2Img.py:generic-api-key:85
5471a8ac2d60026b24f21b51ae6f11db8acd160c:pages/CompareText2Img.py:generic-api-key:92
5471a8ac2d60026b24f21b51ae6f11db8acd160c:daras_ai_v2/img_model_settings_widgets.py:generic-api-key:90
6fca6072032e4f34d7d571e7de8e0ff05f7a487b:static/js/auth.js:generic-api-key:2
2292469b22d97263c7c59cf49fae7281ce96a39c:pages/CompareText2Img.py:generic-api-key:137
aae9d67ed6330a3eb2ede41d5ceeca52a8f0daf4:static/js/auth.js:gcp-api-key:2
d5866242d107743ab5eebeb284e7e5ee2426d941:pages/SocialLookupEmail.py:generic-api-key:181
73bef8c3be7682fed0b99ceb6770f599eabbbd08:daras_ai_v2/send_email.py:generic-api-key:25
fa3f7982fa1527838c2073d2542c83887cc6ebbd:pages/EmailFaceInpainting.py:generic-api-key:189
e1c218882d288ca1df0225654aae8dd10027e9d0:political_example.py:jwt:30
6 changes: 5 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
rev: v4.6.0
hooks:
- id: end-of-file-fixer
- id: check-yaml
Expand All @@ -13,3 +13,7 @@ repos:
entry: poetry run black
language: system
types: [python]
- repo: https://github.com/gitleaks/gitleaks
rev: v8.18.4
hooks:
- id: gitleaks
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,9 @@ docker run \
### 📐 Code Formatting

Use black - https://pypi.org/project/black

### 💣 Secret Scanning

Gitleaks will automatically run pre-commit (see `pre-commit-config.yaml` for details) to prevent commits with secrets in the first place. To test this without committing, run `pre-commit` from the terminal. To skip this check, use `SKIP=gitleaks git commit -m "message"` to commit changes. Preferably, label false positives with the `#gitleaks:allow` comment instead of skipping the check.

Gitleaks will also run in the CI pipeline as a GitHub action on push and pull request (can also be manually triggered in the actions tab on GitHub). To update the baseline of ignored secrets, run `python ./scripts/create_gitleaks_baseline.py` from the venv and commit the changes to `.gitleaksignore`.
2 changes: 1 addition & 1 deletion bots/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ def rerun_tasks(self, request, queryset):
page = Workflow(sr.workflow).page_cls(
request=SimpleNamespace(user=AppUser.objects.get(uid=sr.uid))
)
page.call_runner_task(sr)
page.call_runner_task(sr, deduct_credits=False)
self.message_user(
request,
f"Started re-running {queryset.count()} tasks in the background.",
Expand Down
4 changes: 4 additions & 0 deletions bots/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ def submit_api_call(
request_body: dict,
enable_rate_limits: bool = False,
parent_pr: "PublishedRun" = None,
deduct_credits: bool = True,
) -> tuple["celery.result.AsyncResult", "SavedRun"]:
from routers.api import submit_api_call

Expand All @@ -384,6 +385,7 @@ def submit_api_call(
user=current_user,
request_body=request_body,
enable_rate_limits=enable_rate_limits,
deduct_credits=deduct_credits,
),
)

Expand Down Expand Up @@ -1818,12 +1820,14 @@ def submit_api_call(
current_user: AppUser,
request_body: dict,
enable_rate_limits: bool = False,
deduct_credits: bool = True,
) -> tuple["celery.result.AsyncResult", "SavedRun"]:
return self.saved_run.submit_api_call(
current_user=current_user,
request_body=request_body,
enable_rate_limits=enable_rate_limits,
parent_pr=self,
deduct_credits=deduct_credits,
)


Expand Down
4 changes: 3 additions & 1 deletion celeryapp/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def runner_task(
uid: str,
channel: str,
unsaved_state: dict[str, typing.Any] = None,
deduct_credits: bool = True,
) -> int:
start_time = time()
error_msg = None
Expand Down Expand Up @@ -107,7 +108,8 @@ def save_on_step(yield_val: str | tuple[str, dict] = None, *, done: bool = False

# run completed successfully, deduct credits
else:
sr.transaction, sr.price = page.deduct_credits(gui.session_state)
if deduct_credits:
sr.transaction, sr.price = page.deduct_credits(gui.session_state)

# save everything, mark run as completed
finally:
Expand Down
2 changes: 1 addition & 1 deletion daras_ai_v2/analysis_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def render_analysis_results_page(

gui.session_state.setdefault("selected_graphs", graphs)
selected_graphs = list_view_editor(
add_btn_label="Add a Graph",
add_btn_label="Add a Graph",
key="selected_graphs",
render_inputs=partial(render_inputs, results),
)
Expand Down
46 changes: 28 additions & 18 deletions daras_ai_v2/asr.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,15 @@
"fa", "pl", "pt", "ro", "ru", "sr", "sk", "sl", "es", "sw", "sv", "tl", "ta", "th", "tr", "uk", "ur", "vi", "cy"
} # fmt: skip

# See page 14 of https://scontent-sea1-1.xx.fbcdn.net/v/t39.2365-6/369747868_602316515432698_2401716319310287708_n.pdf?_nc_cat=106&ccb=1-7&_nc_sid=3c67a6&_nc_ohc=_5cpNOcftdYAX8rCrVo&_nc_ht=scontent-sea1-1.xx&oh=00_AfDVkx7XubifELxmB_Un-yEYMJavBHFzPnvTbTlalbd_1Q&oe=65141B39
# https://huggingface.co/facebook/seamless-m4t-v2-large#supported-languages
# For now, below are listed the languages that support ASR. Note that Seamless only accepts ISO 639-3 codes.
SEAMLESS_SUPPORTED = {
"afr", "amh", "arb", "ary", "arz", "asm", "ast", "azj", "bel", "ben", "bos", "bul", "cat", "ceb", "ces", "ckb",
"cmn", "cym", "dan", "deu", "ell", "eng", "est", "eus", "fin", "fra", "gaz", "gle", "glg", "guj", "heb", "hin",
"hrv", "hun", "hye", "ibo", "ind", "isl", "ita", "jav", "jpn", "kam", "kan", "kat", "kaz", "kea", "khk", "khm",
"kir", "kor", "lao", "lit", "ltz", "lug", "luo", "lvs", "mai", "mal", "mar", "mkd", "mlt", "mni", "mya", "nld",
"nno", "nob", "npi", "nya", "oci", "ory", "pan", "pbt", "pes", "pol", "por", "ron", "rus", "slk", "slv", "sna",
"snd", "som", "spa", "srp", "swe", "swh", "tam", "tel", "tgk", "tgl", "tha", "tur", "ukr", "urd", "uzn", "vie",
"xho", "yor", "yue", "zlm", "zul"
SEAMLESS_v2_ASR_SUPPORTED = {
"afr", "amh", "arb", "ary", "arz", "asm", "azj", "bel", "ben", "bos", "bul", "cat", "ceb", "ces", "ckb", "cmn",
"cmn-Hant", "cym", "dan", "deu", "ell", "eng", "est", "eus", "fin", "fra", "fuv", "gaz", "gle", "glg", "guj", "heb",
"hin", "hrv", "hun", "hye", "ibo", "ind", "isl", "ita", "jav", "jpn", "kan", "kat", "kaz", "khk", "khm", "kir",
"kor", "lao", "lit", "lug", "luo", "lvs", "mai", "mal", "mar", "mkd", "mlt", "mni", "mya", "nld", "nno", "nob",
"npi", "nya", "ory", "pan", "pbt", "pes", "pol", "por", "ron", "rus", "slk", "slv", "sna", "snd", "som", "spa",
"srp", "swe", "swh", "tam", "tel", "tgk", "tgl", "tha", "tur", "ukr", "urd", "uzn", "vie", "yor", "yue", "zul",
} # fmt: skip

AZURE_SUPPORTED = {
Expand Down Expand Up @@ -199,7 +198,8 @@
} # fmt: skip

# https://translation.ghananlp.org/api-details#api=ghananlp-translation-webservice-api
GHANA_NLP_SUPPORTED = { 'en': 'English', 'tw': 'Twi', 'gaa': 'Ga', 'ee': 'Ewe', 'fat': 'Fante', 'dag': 'Dagbani', 'gur': 'Gurene', 'yo': 'Yoruba', 'ki': 'Kikuyu', 'luo': 'Luo', 'mer': 'Kimeru' } # fmt: skip
GHANA_NLP_SUPPORTED = {'en': 'English', 'tw': 'Twi', 'gaa': 'Ga', 'ee': 'Ewe', 'fat': 'Fante', 'dag': 'Dagbani',
'gur': 'Gurene', 'yo': 'Yoruba', 'ki': 'Kikuyu', 'luo': 'Luo', 'mer': 'Kimeru'} # fmt: skip
GHANA_NLP_MAXLEN = 500


Expand All @@ -215,11 +215,22 @@ class AsrModels(Enum):
usm = "Chirp / USM (Google V2)"
deepgram = "Deepgram"
azure = "Azure Speech"
seamless_m4t = "Seamless M4T (Facebook Research)"
seamless_m4t_v2 = "Seamless M4T v2 (Facebook Research)"
mms_1b_all = "Massively Multilingual Speech (MMS) (Facebook Research)"

seamless_m4t = "Seamless M4T [Deprecated] (Facebook Research)"

def supports_auto_detect(self) -> bool:
return self not in {self.azure, self.gcp_v1, self.mms_1b_all}
return self not in {
self.azure,
self.gcp_v1,
self.mms_1b_all,
self.seamless_m4t_v2,
}

@classmethod
def _deprecated(cls):
return {cls.seamless_m4t}


asr_model_ids = {
Expand All @@ -230,7 +241,7 @@ def supports_auto_detect(self) -> bool:
AsrModels.vakyansh_bhojpuri: "Harveenchadha/vakyansh-wav2vec2-bhojpuri-bhom-60",
AsrModels.nemo_english: "https://objectstore.e2enetworks.net/indic-asr-public/checkpoints/conformer/english_large_data_fixed.nemo",
AsrModels.nemo_hindi: "https://objectstore.e2enetworks.net/indic-asr-public/checkpoints/conformer/stt_hi_conformer_ctc_large_v2.nemo",
AsrModels.seamless_m4t: "facebook/hf-seamless-m4t-large",
AsrModels.seamless_m4t_v2: "facebook/seamless-m4t-v2-large",
AsrModels.mms_1b_all: "facebook/mms-1b-all",
}

Expand All @@ -248,7 +259,7 @@ def supports_auto_detect(self) -> bool:
AsrModels.gcp_v1: GCP_V1_SUPPORTED,
AsrModels.usm: CHIRP_SUPPORTED,
AsrModels.deepgram: DEEPGRAM_SUPPORTED,
AsrModels.seamless_m4t: SEAMLESS_SUPPORTED,
AsrModels.seamless_m4t_v2: SEAMLESS_v2_ASR_SUPPORTED,
AsrModels.azure: AZURE_SUPPORTED,
AsrModels.mms_1b_all: MMS_SUPPORTED,
}
Expand Down Expand Up @@ -783,15 +794,14 @@ def run_asr(
return "\n".join(
f"Speaker {chunk['speaker']}: {chunk['text']}" for chunk in chunks
)
elif selected_model == AsrModels.seamless_m4t:
elif selected_model == AsrModels.seamless_m4t_v2:
data = call_celery_task(
"seamless",
"seamless.asr",
pipeline=dict(
model_id=asr_model_ids[AsrModels.seamless_m4t],
model_id=asr_model_ids[AsrModels.seamless_m4t_v2],
),
inputs=dict(
audio=audio_url,
task="ASR",
src_lang=language,
),
)
Expand Down
20 changes: 10 additions & 10 deletions daras_ai_v2/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class BasePage:

class RequestModel(BaseModel):
functions: list[RecipeFunction] | None = Field(
title="🧩 Functions",
title="🧩 Developer Tools and Functions",
)
variables: dict[str, typing.Any] = Field(
None,
Expand Down Expand Up @@ -1308,9 +1308,7 @@ def get_credits_click_url(self):
return "/account/"

def get_submit_container_props(self):
return dict(
className="position-sticky bottom-0 bg-white", style=dict(zIndex=100)
)
return dict(className="position-sticky bottom-0 bg-white")

def render_submit_button(self, key="--submit-1"):
with gui.div(**self.get_submit_container_props()):
Expand Down Expand Up @@ -1478,15 +1476,17 @@ def update_flag_for_run(self, run_id: str, uid: str, is_flagged: bool):

# Functions in every recipe feels like overkill for now, hide it in settings
functions_in_settings = True
show_settings = True

def _render_input_col(self):
self.render_form_v2()
placeholder = gui.div()

with gui.expander("⚙️ Settings"):
if self.functions_in_settings:
functions_input(self.request.user)
self.render_settings()
if self.show_settings:
with gui.expander("⚙️ Settings"):
self.render_settings()
if self.functions_in_settings:
functions_input(self.request.user)

with placeholder:
self.render_variables()
Expand All @@ -1501,7 +1501,6 @@ def _render_input_col(self):

def render_variables(self):
if not self.functions_in_settings:
gui.write("---")
functions_input(self.request.user)
variables_input(
template_keys=self.template_keys, allow_add=is_functions_enabled()
Expand Down Expand Up @@ -1687,7 +1686,7 @@ def dump_state_to_sr(self, state: dict, sr: SavedRun):
}
)

def call_runner_task(self, sr: SavedRun):
def call_runner_task(self, sr: SavedRun, deduct_credits: bool = True):
from celeryapp.tasks import runner_task, post_runner_tasks

chain = (
Expand All @@ -1698,6 +1697,7 @@ def call_runner_task(self, sr: SavedRun):
uid=sr.uid,
channel=self.realtime_channel_name(sr.run_id, sr.uid),
unsaved_state=self._unsaved_state(),
deduct_credits=deduct_credits,
)
| post_runner_tasks.s()
)
Expand Down
25 changes: 17 additions & 8 deletions daras_ai_v2/bot_integration_widgets.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import json
from itertools import zip_longest
from textwrap import dedent

import gooey_gui as gui
from django.core.exceptions import ValidationError
from django.db import transaction
from django.utils.text import slugify
from furl import furl

import gooey_gui as gui
from app_users.models import AppUser
from bots.models import BotIntegration, BotIntegrationAnalysisRun, Platform
from daras_ai_v2 import settings, icons
Expand Down Expand Up @@ -94,7 +95,7 @@ def render_workflow_url_input(key: str, del_key: str | None, d: dict):
input_analysis_runs.append(dict(saved_run=sr, published_run=None))

list_view_editor(
add_btn_label="Add",
add_btn_label="Add",
key="analysis_urls",
render_inputs=render_workflow_url_input,
flatten_dict_key="url",
Expand Down Expand Up @@ -311,19 +312,27 @@ def get_bot_test_link(bi: BotIntegration) -> str | None:
return None


def get_web_widget_embed_code(bi: BotIntegration) -> str:
def get_web_widget_embed_code(bi: BotIntegration, *, config: dict = None) -> str:
lib_src = get_app_route_url(
chat_lib_route,
path_params=dict(
integration_id=bi.api_integration_id(),
integration_name=slugify(bi.name) or "untitled",
),
).rstrip("/")
if config is None:
config = {}
return dedent(
f"""
"""
<div id="gooey-embed"></div>
<script async defer onload="GooeyEmbed.mount()" src="{lib_src}"></script>
<script>
function onLoadGooeyEmbed() {
GooeyEmbed.mount(%(config_json)s);
}
</script>
<script async defer onload="onLoadGooeyEmbed()" src="%(lib_src)s"></script>
"""
% dict(config_json=json.dumps(config), lib_src=lib_src)
).strip()


Expand Down Expand Up @@ -375,7 +384,7 @@ def web_widget_config(bi: BotIntegration, user: AppUser | None):
mode="inline",
showSources=True,
enablePhotoUpload=False,
enableLipsyncVideo=False,
autoPlayResponses=True,
enableAudioMessage=True,
branding=(
dict(showPoweredByGooey=True)
Expand All @@ -397,8 +406,8 @@ def web_widget_config(bi: BotIntegration, user: AppUser | None):
config["enableAudioMessage"] = gui.checkbox(
"Enable Audio Message", value=config["enableAudioMessage"]
)
config["enableLipsyncVideo"] = gui.checkbox(
"Enable Lipsync Video", value=config["enableLipsyncVideo"]
config["autoPlayResponses"] = gui.checkbox(
"Auto-play responses", value=config["autoPlayResponses"]
)
# config["branding"]["showPoweredByGooey"] = gui.checkbox(
# "Show Powered By Gooey", value=config["branding"]["showPoweredByGooey"]
Expand Down
Loading

0 comments on commit 0ebcc56

Please sign in to comment.