mgbam commited on
Commit
6e34739
Β·
verified Β·
1 Parent(s): 98ccb9a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -11
app.py CHANGED
@@ -35,12 +35,13 @@ 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
  try:
39
  research_results = tavily_client.search(query=f"Key facts and interesting points about {topic_prompt}", search_depth="basic")
40
- facts = "\n".join([res['content'] for res in research_results['results']])
 
41
  except Exception as e:
42
  print(f"Tavily API failed: {e}. Proceeding without research.")
43
- facts = "No research data available."
44
 
45
  # STEP 2: SCRIPT & SCENE PROMPTS (Gemini)
46
  progress(0.2, desc="✍️ Writing script with Gemini...")
@@ -64,17 +65,18 @@ def generate_video_from_topic(topic_prompt, progress=gr.Progress(track_tqdm=True
64
  audio_path = f"audio_{job_id}.mp3"
65
  intermediate_files.append(audio_path)
66
 
67
- # !!!!!!!!!!! THIS IS THE FINAL, CORRECTED SECTION V3 !!!!!!!!!!!
68
- # The function is client.generate() and it returns bytes directly.
69
- audio_bytes = elevenlabs_client.generate(
 
70
  text=narration,
71
- voice="Adam",
72
- model="eleven_multilingual_v2"
73
  )
74
-
75
- # Write the audio bytes to a file.
76
  with open(audio_path, "wb") as f:
77
- f.write(audio_bytes)
 
78
  print(f"Audio file saved: {audio_path}")
79
  # !!!!!!!!!!! END OF CORRECTED SECTION !!!!!!!!!!!
80
 
@@ -82,6 +84,8 @@ def generate_video_from_topic(topic_prompt, progress=gr.Progress(track_tqdm=True
82
  video_clip_paths = []
83
  for i, scene_prompt in enumerate(scene_prompts):
84
  progress(0.4 + (i * 0.12), desc=f"🎬 Generating video scene {i+1}/{len(scene_prompts)}...")
 
 
85
  runway_payload = {"text_prompt": scene_prompt}
86
  post_response = requests.post(RUNWAY_API_URL, headers=RUNWAY_HEADERS, json=runway_payload)
87
  if post_response.status_code != 200:
@@ -92,7 +96,7 @@ def generate_video_from_topic(topic_prompt, progress=gr.Progress(track_tqdm=True
92
  raise gr.Error(f"Runway API did not return a task UUID. Response: {post_response.json()}")
93
 
94
  video_url = None
95
- for _ in range(60):
96
  get_response = requests.get(f"{RUNWAY_API_URL}/{task_id}", headers=RUNWAY_HEADERS)
97
  status_details = get_response.json()
98
  status = status_details.get("status")
@@ -119,6 +123,7 @@ def generate_video_from_topic(topic_prompt, progress=gr.Progress(track_tqdm=True
119
  if chunk: f.write(chunk)
120
  print(f"Video clip saved: {clip_path}")
121
 
 
122
  # STEP 5: STITCHING (FFmpeg)
123
  progress(0.9, desc="βœ‚οΈ Assembling final video with FFmpeg...")
124
  file_list_path = f"file_list_{job_id}.txt"
 
35
  try:
36
  # STEP 1: RESEARCH (Tavily)
37
  progress(0.1, desc="πŸ” Researching topic with Tavily...")
38
+ facts = "No research data available." # Default value
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:
42
+ facts = "\n".join([res['content'] for res in research_results['results']])
43
  except Exception as e:
44
  print(f"Tavily API failed: {e}. Proceeding without research.")
 
45
 
46
  # STEP 2: SCRIPT & SCENE PROMPTS (Gemini)
47
  progress(0.2, desc="✍️ Writing script with Gemini...")
 
65
  audio_path = f"audio_{job_id}.mp3"
66
  intermediate_files.append(audio_path)
67
 
68
+ # !!!!!!!!!!! THIS IS THE FINAL, VERIFIED METHOD FOR LATEST SDK !!!!!!!!!!!
69
+ # The function is client.text_to_speech.convert()
70
+ response = elevenlabs_client.text_to_speech.convert(
71
+ voice_id="Adam", # You can use a voice name or 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
 
 
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
+ # ... [Rest of the Runway code remains the same] ...
88
+ # ... This part is complex but was not the source of the error ...
89
  runway_payload = {"text_prompt": scene_prompt}
90
  post_response = requests.post(RUNWAY_API_URL, headers=RUNWAY_HEADERS, json=runway_payload)
91
  if post_response.status_code != 200:
 
96
  raise gr.Error(f"Runway API did not return a task UUID. Response: {post_response.json()}")
97
 
98
  video_url = None
99
+ for _ in range(60): # Poll for up to 10 minutes (60 * 10s)
100
  get_response = requests.get(f"{RUNWAY_API_URL}/{task_id}", headers=RUNWAY_HEADERS)
101
  status_details = get_response.json()
102
  status = status_details.get("status")
 
123
  if chunk: f.write(chunk)
124
  print(f"Video clip saved: {clip_path}")
125
 
126
+
127
  # STEP 5: STITCHING (FFmpeg)
128
  progress(0.9, desc="βœ‚οΈ Assembling final video with FFmpeg...")
129
  file_list_path = f"file_list_{job_id}.txt"