Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,7 +18,6 @@ GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
|
| 18 |
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
|
| 19 |
SENTINEL_CLIENT_ID = os.getenv("SENTINEL_CLIENT_ID")
|
| 20 |
SENTINEL_CLIENT_SECRET = os.getenv("SENTINEL_CLIENT_SECRET")
|
| 21 |
-
ELEVENLABS_API_KEY = os.getenv("ELEVENLABS_API_KEY")
|
| 22 |
|
| 23 |
# -------------------- SENTINEL CONFIG --------------------
|
| 24 |
config = SHConfig()
|
|
@@ -79,7 +78,7 @@ def smart_summary(text):
|
|
| 79 |
errors.append(f"HF: {err}")
|
| 80 |
return "β SYSTEM FAILURE. DEBUG LOG:\n" + "\n".join(errors)
|
| 81 |
|
| 82 |
-
# -------------------- AUDIO FUNCTION (
|
| 83 |
def generate_audio_report(text):
|
| 84 |
# 1. Check Library
|
| 85 |
try:
|
|
@@ -91,16 +90,19 @@ def generate_audio_report(text):
|
|
| 91 |
if not text:
|
| 92 |
raise gr.Error("β No text to read!")
|
| 93 |
|
| 94 |
-
# 3. Check Key
|
| 95 |
-
|
|
|
|
|
|
|
| 96 |
if not api_key:
|
| 97 |
-
raise gr.Error("β
|
| 98 |
|
| 99 |
-
# 4. Generate
|
| 100 |
try:
|
| 101 |
-
|
|
|
|
|
|
|
| 102 |
|
| 103 |
-
# Brian's ID: nPczCjzI2devNBz1zQrb
|
| 104 |
audio_stream = client.text_to_speech.convert(
|
| 105 |
text=text[:400],
|
| 106 |
voice_id="nPczCjzI2devNBz1zQrb",
|
|
@@ -114,11 +116,10 @@ def generate_audio_report(text):
|
|
| 114 |
|
| 115 |
except Exception as e:
|
| 116 |
error_msg = str(e)
|
| 117 |
-
# THIS IS THE ERROR YOU ARE SEEING
|
| 118 |
if "401" in error_msg:
|
| 119 |
-
raise gr.Error("β 401 Unauthorized: The
|
| 120 |
elif "quota" in error_msg.lower():
|
| 121 |
-
raise gr.Error("β Quota Exceeded: You have
|
| 122 |
else:
|
| 123 |
raise gr.Error(f"β ElevenLabs Error: {error_msg}")
|
| 124 |
|
|
|
|
| 18 |
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
|
| 19 |
SENTINEL_CLIENT_ID = os.getenv("SENTINEL_CLIENT_ID")
|
| 20 |
SENTINEL_CLIENT_SECRET = os.getenv("SENTINEL_CLIENT_SECRET")
|
|
|
|
| 21 |
|
| 22 |
# -------------------- SENTINEL CONFIG --------------------
|
| 23 |
config = SHConfig()
|
|
|
|
| 78 |
errors.append(f"HF: {err}")
|
| 79 |
return "β SYSTEM FAILURE. DEBUG LOG:\n" + "\n".join(errors)
|
| 80 |
|
| 81 |
+
# -------------------- AUDIO FUNCTION (CLEAN SLATE VERSION) --------------------
|
| 82 |
def generate_audio_report(text):
|
| 83 |
# 1. Check Library
|
| 84 |
try:
|
|
|
|
| 90 |
if not text:
|
| 91 |
raise gr.Error("β No text to read!")
|
| 92 |
|
| 93 |
+
# 3. Check Key (LOOKING FOR NEW NAME)
|
| 94 |
+
# We use a NEW variable name 'EL_KEY' to bypass any stuck errors
|
| 95 |
+
api_key = os.getenv("EL_KEY")
|
| 96 |
+
|
| 97 |
if not api_key:
|
| 98 |
+
raise gr.Error("β Key Missing! Please add the secret 'EL_KEY' in Settings.")
|
| 99 |
|
| 100 |
+
# 4. Generate Audio
|
| 101 |
try:
|
| 102 |
+
# .strip() removes invisible spaces!
|
| 103 |
+
clean_key = api_key.strip()
|
| 104 |
+
client = ElevenLabs(api_key=clean_key)
|
| 105 |
|
|
|
|
| 106 |
audio_stream = client.text_to_speech.convert(
|
| 107 |
text=text[:400],
|
| 108 |
voice_id="nPczCjzI2devNBz1zQrb",
|
|
|
|
| 116 |
|
| 117 |
except Exception as e:
|
| 118 |
error_msg = str(e)
|
|
|
|
| 119 |
if "401" in error_msg:
|
| 120 |
+
raise gr.Error("β 401 Unauthorized: The Key is still rejected by ElevenLabs. Check your account Quota.")
|
| 121 |
elif "quota" in error_msg.lower():
|
| 122 |
+
raise gr.Error("β Quota Exceeded: You have used all your credits.")
|
| 123 |
else:
|
| 124 |
raise gr.Error(f"β ElevenLabs Error: {error_msg}")
|
| 125 |
|