Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -19,7 +19,8 @@ except KeyError as e:
|
|
19 |
raise ValueError(f"API Key Error: Please set the {e} secret in your Hugging Face Space settings.")
|
20 |
|
21 |
# --- 2. DEFINE API ENDPOINTS AND HEADERS ---
|
22 |
-
|
|
|
23 |
RUNWAY_HEADERS = {
|
24 |
"Authorization": f"Bearer {RUNWAY_API_KEY}",
|
25 |
"Content-Type": "application/json"
|
@@ -65,26 +66,31 @@ def generate_video_from_topic(topic_prompt, progress=gr.Progress(track_tqdm=True
|
|
65 |
audio_path = f"audio_{job_id}.mp3"
|
66 |
intermediate_files.append(audio_path)
|
67 |
|
68 |
-
# !!!!!!!!!!! THE FINAL CONFIGURATION !!!!!!!!!!!
|
69 |
-
# Using YOUR personal Voice ID for "Aria" from your VoiceLab.
|
70 |
response = elevenlabs_client.text_to_speech.convert(
|
71 |
voice_id="Xb7hH8MSUJpSbSDYk0k2", # Your personal Voice ID for Aria
|
72 |
text=narration,
|
73 |
model_id="eleven_multilingual_v2"
|
74 |
)
|
75 |
-
|
76 |
with open(audio_path, "wb") as f:
|
77 |
for chunk in response:
|
78 |
f.write(chunk)
|
79 |
print(f"Audio file saved: {audio_path}")
|
80 |
-
# !!!!!!!!!!! END OF CONFIGURATION !!!!!!!!!!!
|
81 |
|
82 |
# STEP 4: VISUALS (Runway)
|
83 |
video_clip_paths = []
|
84 |
for i, scene_prompt in enumerate(scene_prompts):
|
85 |
progress(0.4 + (i * 0.12), desc=f"🎬 Generating video scene {i+1}/{len(scene_prompts)}...")
|
86 |
-
|
87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
if post_response.status_code != 200:
|
89 |
raise gr.Error(f"Runway API Error (start job): {post_response.status_code} - {post_response.text}")
|
90 |
|
@@ -94,7 +100,8 @@ def generate_video_from_topic(topic_prompt, progress=gr.Progress(track_tqdm=True
|
|
94 |
|
95 |
video_url = None
|
96 |
for _ in range(60):
|
97 |
-
|
|
|
98 |
status_details = get_response.json()
|
99 |
status = status_details.get("status")
|
100 |
|
@@ -122,6 +129,7 @@ def generate_video_from_topic(topic_prompt, progress=gr.Progress(track_tqdm=True
|
|
122 |
|
123 |
# STEP 5: STITCHING (FFmpeg)
|
124 |
progress(0.9, desc="✂️ Assembling final video with FFmpeg...")
|
|
|
125 |
file_list_path = f"file_list_{job_id}.txt"
|
126 |
intermediate_files.append(file_list_path)
|
127 |
with open(file_list_path, "w") as f:
|
|
|
19 |
raise ValueError(f"API Key Error: Please set the {e} secret in your Hugging Face Space settings.")
|
20 |
|
21 |
# --- 2. DEFINE API ENDPOINTS AND HEADERS ---
|
22 |
+
# The base URL for V2 tasks
|
23 |
+
RUNWAY_API_URL = "https://api.runwayml.com/v2"
|
24 |
RUNWAY_HEADERS = {
|
25 |
"Authorization": f"Bearer {RUNWAY_API_KEY}",
|
26 |
"Content-Type": "application/json"
|
|
|
66 |
audio_path = f"audio_{job_id}.mp3"
|
67 |
intermediate_files.append(audio_path)
|
68 |
|
|
|
|
|
69 |
response = elevenlabs_client.text_to_speech.convert(
|
70 |
voice_id="Xb7hH8MSUJpSbSDYk0k2", # Your personal Voice ID for Aria
|
71 |
text=narration,
|
72 |
model_id="eleven_multilingual_v2"
|
73 |
)
|
|
|
74 |
with open(audio_path, "wb") as f:
|
75 |
for chunk in response:
|
76 |
f.write(chunk)
|
77 |
print(f"Audio file saved: {audio_path}")
|
|
|
78 |
|
79 |
# STEP 4: VISUALS (Runway)
|
80 |
video_clip_paths = []
|
81 |
for i, scene_prompt in enumerate(scene_prompts):
|
82 |
progress(0.4 + (i * 0.12), desc=f"🎬 Generating video scene {i+1}/{len(scene_prompts)}...")
|
83 |
+
|
84 |
+
# !!!!!!!!!!! THE FINAL, VERIFIED RUNWAY FIX !!!!!!!!!!!
|
85 |
+
# 1. The payload now includes the task_type
|
86 |
+
runway_payload = {
|
87 |
+
"task_type": "gen2",
|
88 |
+
"text_prompt": scene_prompt
|
89 |
+
}
|
90 |
+
# 2. The POST request goes to the base URL /tasks
|
91 |
+
post_response = requests.post(f"{RUNWAY_API_URL}/tasks", headers=RUNWAY_HEADERS, json=runway_payload)
|
92 |
+
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
93 |
+
|
94 |
if post_response.status_code != 200:
|
95 |
raise gr.Error(f"Runway API Error (start job): {post_response.status_code} - {post_response.text}")
|
96 |
|
|
|
100 |
|
101 |
video_url = None
|
102 |
for _ in range(60):
|
103 |
+
# Polling URL also needs the V2 base
|
104 |
+
get_response = requests.get(f"{RUNWAY_API_URL}/tasks/{task_id}", headers=RUNWAY_HEADERS)
|
105 |
status_details = get_response.json()
|
106 |
status = status_details.get("status")
|
107 |
|
|
|
129 |
|
130 |
# STEP 5: STITCHING (FFmpeg)
|
131 |
progress(0.9, desc="✂️ Assembling final video with FFmpeg...")
|
132 |
+
# ... (Rest of the code is unchanged and correct)
|
133 |
file_list_path = f"file_list_{job_id}.txt"
|
134 |
intermediate_files.append(file_list_path)
|
135 |
with open(file_list_path, "w") as f:
|