mgbam commited on
Commit
cf6ac3a
·
verified ·
1 Parent(s): 3d42adf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -12
app.py CHANGED
@@ -19,7 +19,6 @@ 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
- # 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}",
@@ -81,15 +80,11 @@ def generate_video_from_topic(topic_prompt, progress=gr.Progress(track_tqdm=True
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}")
@@ -100,7 +95,7 @@ def generate_video_from_topic(topic_prompt, progress=gr.Progress(track_tqdm=True
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")
@@ -129,7 +124,6 @@ def generate_video_from_topic(topic_prompt, progress=gr.Progress(track_tqdm=True
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:
 
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
  RUNWAY_API_URL = "https://api.runwayml.com/v2"
23
  RUNWAY_HEADERS = {
24
  "Authorization": f"Bearer {RUNWAY_API_KEY}",
 
80
  for i, scene_prompt in enumerate(scene_prompts):
81
  progress(0.4 + (i * 0.12), desc=f"🎬 Generating video scene {i+1}/{len(scene_prompts)}...")
82
 
83
+ # !!!!!!!!!!! THE FINAL, VERIFIED RUNWAY FIX V2 !!!!!!!!!!!
84
+ runway_payload = {"text_prompt": scene_prompt}
85
+ # The POST request goes to the specific /tasks/gen2 endpoint
86
+ post_response = requests.post(f"{RUNWAY_API_URL}/tasks/gen2", headers=RUNWAY_HEADERS, json=runway_payload)
87
+ # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
 
 
 
88
 
89
  if post_response.status_code != 200:
90
  raise gr.Error(f"Runway API Error (start job): {post_response.status_code} - {post_response.text}")
 
95
 
96
  video_url = None
97
  for _ in range(60):
98
+ # Polling URL is general and correct
99
  get_response = requests.get(f"{RUNWAY_API_URL}/tasks/{task_id}", headers=RUNWAY_HEADERS)
100
  status_details = get_response.json()
101
  status = status_details.get("status")
 
124
 
125
  # STEP 5: STITCHING (FFmpeg)
126
  progress(0.9, desc="✂️ Assembling final video with FFmpeg...")
 
127
  file_list_path = f"file_list_{job_id}.txt"
128
  intermediate_files.append(file_list_path)
129
  with open(file_list_path, "w") as f: