Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -38,19 +38,20 @@ def format_prompt(message, history, system_prompt=None):
|
|
38 |
prompt += f"[INST] {message} [/INST]"
|
39 |
return prompt
|
40 |
|
41 |
-
def generate_voice(text, voice_name, api_key):
|
42 |
set_api_key(elevenlabs_api_key) #set API key
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
54 |
|
55 |
def generate(
|
56 |
prompt, history, enable_tts, tts_password, temperature=0.2, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0
|
@@ -142,32 +143,19 @@ def generate(
|
|
142 |
# Check if the checkbox is selected and the correct password is provided
|
143 |
|
144 |
|
145 |
-
checkbox = gr.Checkbox(label="Enable TTS")
|
146 |
passwordInput = gr.Textbox(label="TTS Password", type="password")
|
147 |
-
passwordConfirm = gr.Button(value="Confirm")
|
148 |
mychatbot = gr.Chatbot(avatar_images=["./user.png", "./stella.jpg"], bubble_full_width=False, show_label=False, show_copy_button=True, likeable=True)
|
149 |
|
150 |
-
with mychatbot.change:
|
151 |
-
enable_tts = checkbox
|
152 |
-
|
153 |
-
def ttsEnable():
|
154 |
-
if checkbox == True and passwordInput == ttsPassword:
|
155 |
-
enable_tts = True
|
156 |
-
|
157 |
-
elif checkbox == True and passwordInput != ttsPassword:
|
158 |
-
gr.Warning("Incorrect Password!")
|
159 |
-
|
160 |
-
passwordConfirm.click(fn=ttsEnable)
|
161 |
-
|
162 |
-
if enable_tts == True:
|
163 |
-
|
164 |
chat = gr.ChatInterface(
|
165 |
fn=generate,
|
166 |
chatbot=mychatbot,
|
167 |
title="Stella ",
|
168 |
retry_btn=None,
|
169 |
undo_btn=None,
|
170 |
-
additional_inputs=[
|
171 |
)
|
172 |
|
|
|
|
|
|
|
173 |
chat.launch(show_api=False)
|
|
|
38 |
prompt += f"[INST] {message} [/INST]"
|
39 |
return prompt
|
40 |
|
41 |
+
def generate_voice(text, voice_name, api_key, tts_password):
|
42 |
set_api_key(elevenlabs_api_key) #set API key
|
43 |
+
if tts_password == ttsPassword:
|
44 |
+
try:
|
45 |
+
audio = generate(
|
46 |
+
voice=voice_name,
|
47 |
+
model="eleven_multilingual_v2"
|
48 |
+
)
|
49 |
+
print("Generating voice...")
|
50 |
+
return (44100, np.frombuffer(pad_buffer(audio), dtype=np.int16))
|
51 |
+
except UnauthenticatedRateLimitError as e:
|
52 |
+
raise gr.Error("Thanks for trying out ElevenLabs TTS! You've reached the free tier limit. Please provide an API key to continue.")
|
53 |
+
except Exception as e:
|
54 |
+
raise gr.Error(e)
|
55 |
|
56 |
def generate(
|
57 |
prompt, history, enable_tts, tts_password, temperature=0.2, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0
|
|
|
143 |
# Check if the checkbox is selected and the correct password is provided
|
144 |
|
145 |
|
|
|
146 |
passwordInput = gr.Textbox(label="TTS Password", type="password")
|
|
|
147 |
mychatbot = gr.Chatbot(avatar_images=["./user.png", "./stella.jpg"], bubble_full_width=False, show_label=False, show_copy_button=True, likeable=True)
|
148 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
chat = gr.ChatInterface(
|
150 |
fn=generate,
|
151 |
chatbot=mychatbot,
|
152 |
title="Stella ",
|
153 |
retry_btn=None,
|
154 |
undo_btn=None,
|
155 |
+
additional_inputs=[passwordInput],
|
156 |
)
|
157 |
|
158 |
+
with chat:
|
159 |
+
generate_voice(passwordInput);
|
160 |
+
|
161 |
chat.launch(show_api=False)
|