Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,40 +14,51 @@ HF_TOKEN = os.environ.get("HF_TOKEN")
|
|
| 14 |
if not AGNES_API_KEY:
|
| 15 |
print("⚠️ AGNES_API_KEY not set! Get from video.lichuanyang.top")
|
| 16 |
|
| 17 |
-
# ===== AGNES
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
def generate_video_agnes(prompt, duration=45):
|
| 21 |
"""Generate video using Agnes AI API"""
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
| 42 |
if video_b64:
|
| 43 |
return f"data:video/mp4;base64,{video_b64}"
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
-
# ===== HUGGING FACE TTS (
|
| 51 |
def generate_audio_hf(text, lang, voice):
|
| 52 |
try:
|
| 53 |
if not HF_TOKEN:
|
|
|
|
| 14 |
if not AGNES_API_KEY:
|
| 15 |
print("⚠️ AGNES_API_KEY not set! Get from video.lichuanyang.top")
|
| 16 |
|
| 17 |
+
# ===== AGNES API (Multiple endpoints to try) =====
|
| 18 |
+
AGNES_ENDPOINTS = [
|
| 19 |
+
"https://video.lichuanyang.top/api/generate",
|
| 20 |
+
"https://video.lichuanyang.top/v1/generate",
|
| 21 |
+
"https://video.lichuanyang.top/generate"
|
| 22 |
+
]
|
| 23 |
|
| 24 |
def generate_video_agnes(prompt, duration=45):
|
| 25 |
"""Generate video using Agnes AI API"""
|
| 26 |
+
headers = {
|
| 27 |
+
"Authorization": f"Bearer {AGNES_API_KEY}",
|
| 28 |
+
"Content-Type": "application/json"
|
| 29 |
+
}
|
| 30 |
+
payload = {
|
| 31 |
+
"prompt": prompt,
|
| 32 |
+
"duration": min(duration, 60)
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
for endpoint in AGNES_ENDPOINTS:
|
| 36 |
+
try:
|
| 37 |
+
print(f"🔄 Trying Agnes endpoint: {endpoint}")
|
| 38 |
+
response = requests.post(endpoint, json=payload, headers=headers, timeout=120)
|
| 39 |
+
|
| 40 |
+
if response.status_code == 200:
|
| 41 |
+
data = response.json()
|
| 42 |
+
# Check for video URL or base64
|
| 43 |
+
video_url = data.get("video_url") or data.get("url") or data.get("output")
|
| 44 |
+
if video_url:
|
| 45 |
+
return video_url
|
| 46 |
+
video_b64 = data.get("video_base64") or data.get("data")
|
| 47 |
if video_b64:
|
| 48 |
return f"data:video/mp4;base64,{video_b64}"
|
| 49 |
+
# If response is direct video bytes
|
| 50 |
+
if response.headers.get("content-type", "").startswith("video/"):
|
| 51 |
+
video_b64 = base64.b64encode(response.content).decode('utf-8')
|
| 52 |
+
return f"data:video/mp4;base64,{video_b64}"
|
| 53 |
+
print(f"⚠️ No video data in response: {data}")
|
| 54 |
+
else:
|
| 55 |
+
print(f"❌ Agnes endpoint {endpoint} failed: {response.status_code} - {response.text[:100]}")
|
| 56 |
+
except Exception as e:
|
| 57 |
+
print(f"❌ Agnes endpoint error: {str(e)}")
|
| 58 |
+
|
| 59 |
+
raise Exception("All Agnes endpoints failed")
|
| 60 |
|
| 61 |
+
# ===== HUGGING FACE TTS (optional audio) =====
|
| 62 |
def generate_audio_hf(text, lang, voice):
|
| 63 |
try:
|
| 64 |
if not HF_TOKEN:
|