Skip to content

Commit

Permalink
make eleven labs credits a user error
Browse files Browse the repository at this point in the history
  • Loading branch information
devxpy committed Feb 18, 2024
1 parent 0b84904 commit 1f837d0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
3 changes: 2 additions & 1 deletion daras_ai/image_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from furl import furl

from daras_ai_v2 import settings
from daras_ai_v2.exceptions import UserError


def resize_img_pad(img_bytes: bytes, size: tuple[int, int]) -> bytes:
Expand Down Expand Up @@ -90,7 +91,7 @@ def bytes_to_cv2_img(img_bytes: bytes, greyscale=False) -> np.ndarray:
flags = cv2.IMREAD_COLOR
img_cv2 = cv2.imdecode(np.frombuffer(img_bytes, dtype=np.uint8), flags=flags)
if not img_exists(img_cv2):
raise ValueError("Bad Image")
raise UserError("Bad Image")
return img_cv2


Expand Down
13 changes: 8 additions & 5 deletions recipes/TextToSpeech.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from daras_ai.image_input import upload_file_from_bytes, storage_blob_for
from daras_ai_v2 import settings
from daras_ai_v2.base import BasePage
from daras_ai_v2.exceptions import raise_for_status
from daras_ai_v2.exceptions import raise_for_status, UserError
from daras_ai_v2.gpu_server import GpuEndpoints, call_celery_task_outfile
from daras_ai_v2.loom_video_widget import youtube_video
from daras_ai_v2.text_to_speech_settings_widgets import (
Expand Down Expand Up @@ -254,13 +254,16 @@ def run(self, state: dict):

case TextToSpeechProviders.ELEVEN_LABS:
xi_api_key, is_custom_key = self._get_elevenlabs_api_key(state)
assert (
if not (
is_custom_key
or self.is_current_user_paying()
or self.is_current_user_admin()
), """
Please purchase Gooey.AI credits to use ElevenLabs voices <a href="/account">here</a>.
"""
):
raise UserError(
"""
Please purchase Gooey.AI credits to use ElevenLabs voices <a href="/account">here</a>.
"""
)

voice_model = self._get_elevenlabs_voice_model(state)
voice_id = self._get_elevenlabs_voice_id(state)
Expand Down
10 changes: 6 additions & 4 deletions recipes/VideoBots.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,12 +621,14 @@ def additional_notes(self):
def run(self, state: dict) -> typing.Iterator[str | None]:
request: VideoBotsPage.RequestModel = self.RequestModel.parse_obj(state)

if state.get("tts_provider") == TextToSpeechProviders.ELEVEN_LABS.name:
assert (
self.is_current_user_paying() or self.is_current_user_admin()
), """
if state.get("tts_provider") == TextToSpeechProviders.ELEVEN_LABS.name and not (
self.is_current_user_paying() or self.is_current_user_admin()
):
raise UserError(
"""
Please purchase Gooey.AI credits to use ElevenLabs voices <a href="/account">here</a>.
"""
)

user_input = request.input_prompt.strip()
if not (user_input or request.input_images or request.input_documents):
Expand Down

0 comments on commit 1f837d0

Please sign in to comment.