Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,7 +18,7 @@ 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 |
-
|
| 22 |
|
| 23 |
# -------------------- SENTINEL CONFIG --------------------
|
| 24 |
config = SHConfig()
|
|
@@ -79,51 +79,46 @@ 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 |
-
|
| 85 |
-
Attempts to generate audio and raises a VISIBLE ERROR if it fails.
|
| 86 |
-
"""
|
| 87 |
-
# 1. Check if Library is Installed
|
| 88 |
try:
|
| 89 |
from elevenlabs.client import ElevenLabs
|
| 90 |
except ImportError:
|
| 91 |
-
raise gr.Error("β 'elevenlabs'
|
| 92 |
|
| 93 |
-
# 2. Check
|
| 94 |
if not text:
|
| 95 |
-
raise gr.Error("β No text to read!
|
| 96 |
|
| 97 |
-
# 3. Check
|
| 98 |
api_key = os.getenv("ELEVENLABS_API_KEY")
|
| 99 |
if not api_key:
|
| 100 |
-
raise gr.Error("β API Key Missing!
|
| 101 |
|
| 102 |
-
# 4. Generate
|
| 103 |
try:
|
| 104 |
-
# Connect strictly inside the function to ensure the key is fresh
|
| 105 |
client = ElevenLabs(api_key=api_key)
|
| 106 |
|
| 107 |
-
#
|
| 108 |
-
|
|
|
|
| 109 |
text=text[:400],
|
| 110 |
-
|
| 111 |
-
|
| 112 |
)
|
| 113 |
|
| 114 |
-
# Save to temp file
|
| 115 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as f:
|
| 116 |
for chunk in audio_stream:
|
| 117 |
f.write(chunk)
|
| 118 |
return f.name
|
| 119 |
|
| 120 |
except Exception as e:
|
| 121 |
-
# Display the specific error from ElevenLabs
|
| 122 |
error_msg = str(e)
|
| 123 |
if "401" in error_msg:
|
| 124 |
-
raise gr.Error("β 401 Unauthorized:
|
| 125 |
elif "quota" in error_msg.lower():
|
| 126 |
-
raise gr.Error("β Quota Exceeded:
|
| 127 |
else:
|
| 128 |
raise gr.Error(f"β ElevenLabs Error: {error_msg}")
|
| 129 |
|
|
@@ -243,9 +238,7 @@ custom_css = """
|
|
| 243 |
#analyze-btn { background: linear-gradient(90deg, #0061ff 0%, #60efff 100%); color: white; border: none; }
|
| 244 |
"""
|
| 245 |
|
| 246 |
-
# !!! CSS FIX APPLIED HERE !!!
|
| 247 |
with gr.Blocks(title="FlumenIntel") as demo:
|
| 248 |
-
# Inject CSS using gr.HTML instead of the 'css' argument
|
| 249 |
gr.HTML(f"<style>{custom_css}</style>")
|
| 250 |
|
| 251 |
with gr.Column(elem_id="title-box"):
|
|
|
|
| 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 |
errors.append(f"HF: {err}")
|
| 80 |
return "β SYSTEM FAILURE. DEBUG LOG:\n" + "\n".join(errors)
|
| 81 |
|
| 82 |
+
# -------------------- AUDIO FUNCTION (UPDATED FOR V1.0) --------------------
|
| 83 |
def generate_audio_report(text):
|
| 84 |
+
# 1. Check Library
|
|
|
|
|
|
|
|
|
|
| 85 |
try:
|
| 86 |
from elevenlabs.client import ElevenLabs
|
| 87 |
except ImportError:
|
| 88 |
+
raise gr.Error("β Library Missing! Add 'elevenlabs' to requirements.txt")
|
| 89 |
|
| 90 |
+
# 2. Check Text
|
| 91 |
if not text:
|
| 92 |
+
raise gr.Error("β No text to read!")
|
| 93 |
|
| 94 |
+
# 3. Check Key
|
| 95 |
api_key = os.getenv("ELEVENLABS_API_KEY")
|
| 96 |
if not api_key:
|
| 97 |
+
raise gr.Error("β API Key Missing! Check Settings > Secrets.")
|
| 98 |
|
| 99 |
+
# 4. Generate with NEW Syntax
|
| 100 |
try:
|
|
|
|
| 101 |
client = ElevenLabs(api_key=api_key)
|
| 102 |
|
| 103 |
+
# Use 'text_to_speech.convert' instead of 'generate'
|
| 104 |
+
# Voice ID for "Brian": nPczCjzI2devNBz1zQrb
|
| 105 |
+
audio_stream = client.text_to_speech.convert(
|
| 106 |
text=text[:400],
|
| 107 |
+
voice_id="nPczCjzI2devNBz1zQrb",
|
| 108 |
+
model_id="eleven_multilingual_v2"
|
| 109 |
)
|
| 110 |
|
|
|
|
| 111 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as f:
|
| 112 |
for chunk in audio_stream:
|
| 113 |
f.write(chunk)
|
| 114 |
return f.name
|
| 115 |
|
| 116 |
except Exception as e:
|
|
|
|
| 117 |
error_msg = str(e)
|
| 118 |
if "401" in error_msg:
|
| 119 |
+
raise gr.Error("β 401 Unauthorized: API Key is wrong.")
|
| 120 |
elif "quota" in error_msg.lower():
|
| 121 |
+
raise gr.Error("β Quota Exceeded: No credits left.")
|
| 122 |
else:
|
| 123 |
raise gr.Error(f"β ElevenLabs Error: {error_msg}")
|
| 124 |
|
|
|
|
| 238 |
#analyze-btn { background: linear-gradient(90deg, #0061ff 0%, #60efff 100%); color: white; border: none; }
|
| 239 |
"""
|
| 240 |
|
|
|
|
| 241 |
with gr.Blocks(title="FlumenIntel") as demo:
|
|
|
|
| 242 |
gr.HTML(f"<style>{custom_css}</style>")
|
| 243 |
|
| 244 |
with gr.Column(elem_id="title-box"):
|