Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
|
|
|
|
|
|
| 3 |
from openai import OpenAI
|
| 4 |
|
| 5 |
# Initialize OpenAI API client with API key
|
|
@@ -20,20 +22,21 @@ def generate_speech(input_text):
|
|
| 20 |
# Extract generated text (response by the assistant) from OpenAI's API response
|
| 21 |
message_content = completion.choices[0].message.content.strip() # Remove whitespace from the ends
|
| 22 |
|
| 23 |
-
#
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
| 37 |
|
| 38 |
# Define the Gradio interface
|
| 39 |
iface = gr.Interface(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
+
import requests
|
| 4 |
+
import re
|
| 5 |
from openai import OpenAI
|
| 6 |
|
| 7 |
# Initialize OpenAI API client with API key
|
|
|
|
| 22 |
# Extract generated text (response by the assistant) from OpenAI's API response
|
| 23 |
message_content = completion.choices[0].message.content.strip() # Remove whitespace from the ends
|
| 24 |
|
| 25 |
+
# Prepare the text for TTS conversion (you may want to process the text further)
|
| 26 |
+
#text_to_speech = message_content
|
| 27 |
+
|
| 28 |
+
response = client.audio.speech.create(
|
| 29 |
+
model="tts-1",
|
| 30 |
+
voice="alloy",
|
| 31 |
+
input=str(message_content)
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
# Return the response content directly if successful, otherwise print error details
|
| 35 |
+
if response.status_code == 200:
|
| 36 |
+
return response.content
|
| 37 |
+
else:
|
| 38 |
+
print("Error with ElevenLabs API:", response.status_code, response.text)
|
| 39 |
+
raise Exception(f"Failed to generate speech, status code: {response.status_code}, response: {response.text}")
|
| 40 |
|
| 41 |
# Define the Gradio interface
|
| 42 |
iface = gr.Interface(
|