gopallikehack commited on
Commit
bf51ec0
·
verified ·
1 Parent(s): 0813a4c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -28
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 AI API =====
18
- AGNES_API = "https://video.lichuanyang.top/video/generate"
 
 
 
 
19
 
20
  def generate_video_agnes(prompt, duration=45):
21
  """Generate video using Agnes AI API"""
22
- try:
23
- headers = {
24
- "Authorization": f"Bearer {AGNES_API_KEY}",
25
- "Content-Type": "application/json"
26
- }
27
- payload = {
28
- "prompt": prompt,
29
- "duration": min(duration, 60),
30
- "style": "cinematic"
31
- }
32
- response = requests.post(AGNES_API, json=payload, headers=headers, timeout=120)
33
-
34
- if response.status_code == 200:
35
- data = response.json()
36
- video_url = data.get("video_url")
37
- if video_url:
38
- return video_url
39
- else:
40
- # If video is generated as base64
41
- video_b64 = data.get("video_base64")
 
42
  if video_b64:
43
  return f"data:video/mp4;base64,{video_b64}"
44
- raise Exception("No video URL or base64 in response")
45
- else:
46
- raise Exception(f"Agnes API error: {response.status_code} - {response.text[:100]}")
47
- except Exception as e:
48
- raise Exception(f"Agnes video error: {str(e)}")
 
 
 
 
 
 
49
 
50
- # ===== HUGGING FACE TTS (for audio) =====
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: