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"
|
@@ -35,7 +36,7 @@ def generate_video_from_topic(topic_prompt, progress=gr.Progress(track_tqdm=True
|
|
35 |
try:
|
36 |
# STEP 1: RESEARCH (Tavily)
|
37 |
progress(0.1, desc="π Researching topic with Tavily...")
|
38 |
-
facts = "No research data available."
|
39 |
try:
|
40 |
research_results = tavily_client.search(query=f"Key facts and interesting points about {topic_prompt}", search_depth="basic")
|
41 |
if research_results and 'results' in research_results:
|
@@ -65,27 +66,22 @@ 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 FIX !!!!!!!!!!!
|
69 |
-
# We now use the official Voice ID for "Adam" instead of the name.
|
70 |
response = elevenlabs_client.text_to_speech.convert(
|
71 |
-
voice_id="
|
72 |
text=narration,
|
73 |
model_id="eleven_multilingual_v2"
|
74 |
)
|
75 |
-
|
76 |
-
# Write the streamed audio chunks to a file.
|
77 |
with open(audio_path, "wb") as f:
|
78 |
for chunk in response:
|
79 |
f.write(chunk)
|
80 |
print(f"Audio file saved: {audio_path}")
|
81 |
-
# !!!!!!!!!!! END OF CORRECTED SECTION !!!!!!!!!!!
|
82 |
|
83 |
# STEP 4: VISUALS (Runway)
|
84 |
video_clip_paths = []
|
85 |
for i, scene_prompt in enumerate(scene_prompts):
|
86 |
progress(0.4 + (i * 0.12), desc=f"π¬ Generating video scene {i+1}/{len(scene_prompts)}...")
|
87 |
runway_payload = {"text_prompt": scene_prompt}
|
88 |
-
post_response = requests.post(RUNWAY_API_URL, headers=RUNWAY_HEADERS, json=runway_payload)
|
89 |
if post_response.status_code != 200:
|
90 |
raise gr.Error(f"Runway API Error (start job): {post_response.status_code} - {post_response.text}")
|
91 |
|
@@ -95,7 +91,8 @@ def generate_video_from_topic(topic_prompt, progress=gr.Progress(track_tqdm=True
|
|
95 |
|
96 |
video_url = None
|
97 |
for _ in range(60):
|
98 |
-
|
|
|
99 |
status_details = get_response.json()
|
100 |
status = status_details.get("status")
|
101 |
|
|
|
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 FIRST FIX: Use the correct V2 endpoint !!!!!!!!!!!
|
23 |
+
RUNWAY_API_URL = "https://api.runwayml.com/v2/tasks"
|
24 |
RUNWAY_HEADERS = {
|
25 |
"Authorization": f"Bearer {RUNWAY_API_KEY}",
|
26 |
"Content-Type": "application/json"
|
|
|
36 |
try:
|
37 |
# STEP 1: RESEARCH (Tavily)
|
38 |
progress(0.1, desc="π Researching topic with Tavily...")
|
39 |
+
facts = "No research data available."
|
40 |
try:
|
41 |
research_results = tavily_client.search(query=f"Key facts and interesting points about {topic_prompt}", search_depth="basic")
|
42 |
if research_results and 'results' in research_results:
|
|
|
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="oWAxZDx7w5z9imAaTrzz", # Official ID for Adam
|
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 |
runway_payload = {"text_prompt": scene_prompt}
|
84 |
+
post_response = requests.post(f"{RUNWAY_API_URL}/text-to-video", headers=RUNWAY_HEADERS, json=runway_payload)
|
85 |
if post_response.status_code != 200:
|
86 |
raise gr.Error(f"Runway API Error (start job): {post_response.status_code} - {post_response.text}")
|
87 |
|
|
|
91 |
|
92 |
video_url = None
|
93 |
for _ in range(60):
|
94 |
+
# !!!!!!!!!!! THE SECOND FIX: Use the correct V2 polling URL !!!!!!!!!!!
|
95 |
+
get_response = requests.get(f"https://api.runwayml.com/v2/tasks/{task_id}", headers=RUNWAY_HEADERS)
|
96 |
status_details = get_response.json()
|
97 |
status = status_details.get("status")
|
98 |
|