Skip to content

Commit

Permalink
- show unsaved state in api tab
Browse files Browse the repository at this point in the history
- load 11labs key from session state to show in api tab request
  • Loading branch information
devxpy committed Jul 24, 2024
1 parent 678db4d commit 0c48fd8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
2 changes: 1 addition & 1 deletion daras_ai_v2/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2072,7 +2072,7 @@ def run_as_api_tab(self):

api_example_generator(
api_url=api_url,
request_body=request_body,
request_body=request_body | self._unsaved_state(),
as_form_data=as_form_data,
as_async=as_async,
)
Expand Down
38 changes: 22 additions & 16 deletions daras_ai_v2/text_to_speech_settings_widgets.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
from enum import Enum
import typing
from enum import Enum

import requests
from furl import furl
from daras_ai_v2.azure_asr import azure_auth_header

import gooey_ui as st
from daras_ai_v2 import settings
from daras_ai_v2.azure_asr import azure_auth_header
from daras_ai_v2.custom_enum import GooeyEnum
from daras_ai_v2.enum_selector_widget import enum_selector
from daras_ai_v2.exceptions import raise_for_status
from daras_ai_v2.redis_cache import redis_cache_decorator

if typing.TYPE_CHECKING:
from daras_ai_v2.base import BasePage

SESSION_ELEVENLABS_API_KEY = "__user__elevenlabs_api_key"

UBERDUCK_VOICES = {
Expand Down Expand Up @@ -329,20 +332,8 @@ def uberduck_settings():
)


def elevenlabs_selector(page):
if not st.session_state.get("elevenlabs_api_key"):
st.session_state["elevenlabs_api_key"] = page.request.session.get(
SESSION_ELEVENLABS_API_KEY
)

# for backwards compat
if old_voice_name := st.session_state.pop("elevenlabs_voice_name", None):
try:
st.session_state["elevenlabs_voice_id"] = OLD_ELEVEN_LABS_VOICES[
old_voice_name
]
except KeyError:
pass
def elevenlabs_selector(page: "BasePage"):
elevenlabs_init_state(page)

elevenlabs_use_custom_key = st.checkbox(
"Use custom API key + Voice ID",
Expand Down Expand Up @@ -406,6 +397,21 @@ def elevenlabs_selector(page):
)


def elevenlabs_init_state(page: "BasePage"):
if not st.session_state.get("elevenlabs_api_key"):
st.session_state["elevenlabs_api_key"] = page.request.session.get(
SESSION_ELEVENLABS_API_KEY
)
# for backwards compat
if old_voice_name := st.session_state.pop("elevenlabs_voice_name", None):
try:
st.session_state["elevenlabs_voice_id"] = OLD_ELEVEN_LABS_VOICES[
old_voice_name
]
except KeyError:
pass


def elevenlabs_settings():
col1, col2 = st.columns(2)
with col1:
Expand Down
5 changes: 5 additions & 0 deletions recipes/TextToSpeech.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
OpenAI_TTS_Models,
OpenAI_TTS_Voices,
OLD_ELEVEN_LABS_VOICES,
elevenlabs_init_state,
)

DEFAULT_TTS_META_IMG = "https://storage.googleapis.com/dara-c1b52.appspot.com/daras_ai/media/a73181ce-9457-11ee-8edd-02420a0001c7/Voice%20generators.jpg.png"
Expand Down Expand Up @@ -108,6 +109,10 @@ def fields_to_save(self):
pass
return fields

def run_as_api_tab(self):
elevenlabs_init_state(self)
super().run_as_api_tab()

def preview_description(self, state: dict) -> str:
return "Input your text, pick a voice & a Text-to-Speech AI engine to create audio. Compare the best voice generators from Google, UberDuck.ai & more to add automated voices to your podcast, YouTube videos, website, or app."

Expand Down
5 changes: 5 additions & 0 deletions recipes/VideoBots.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
TextToSpeechProviders,
text_to_speech_settings,
text_to_speech_provider_selector,
elevenlabs_init_state,
)
from daras_ai_v2.vector_search import DocSearchRequest
from functions.recipe_functions import LLMTools
Expand Down Expand Up @@ -556,6 +557,10 @@ def fields_to_save(self) -> [str]:
pass
return fields

def run_as_api_tab(self):
elevenlabs_init_state(self)
super().run_as_api_tab()

def render_example(self, state: dict):
input_prompt = state.get("input_prompt")
if input_prompt:
Expand Down

0 comments on commit 0c48fd8

Please sign in to comment.