mgbam commited on
Commit
83a9b0b
·
verified ·
1 Parent(s): 8b30fd7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -10
app.py CHANGED
@@ -1,7 +1,6 @@
1
  import gradio as gr
2
  import os
3
  import google.generativeai as genai
4
- # --- CHANGE 1: Import the new ElevenLabs client ---
5
  from elevenlabs.client import ElevenLabs
6
  from tavily import TavilyClient
7
  import requests
@@ -15,10 +14,7 @@ try:
15
  genai.configure(api_key=os.environ["GEMINI_API_KEY"])
16
  tavily_client = TavilyClient(api_key=os.environ["TAVILY_API_KEY"])
17
  RUNWAY_API_KEY = os.environ["RUNWAY_API_KEY"]
18
-
19
- # --- CHANGE 2: Create an instance of the ElevenLabs client ---
20
  elevenlabs_client = ElevenLabs(api_key=os.environ["ELEVENLABS_API_KEY"])
21
-
22
  except KeyError as e:
23
  raise ValueError(f"API Key Error: Please set the {e} secret in your Hugging Face Space settings.")
24
 
@@ -77,14 +73,16 @@ def generate_video_from_topic(topic_prompt, progress=gr.Progress(track_tqdm=True
77
  audio_path = f"audio_{job_id}.mp3"
78
  intermediate_files.append(audio_path)
79
 
80
- # --- CHANGE 3: Use the client instance to generate audio ---
81
- audio_bytes = elevenlabs_client.generate(
82
  text=narration,
83
- voice="Adam",
84
  model="eleven_multilingual_v2"
85
  )
 
86
  with open(audio_path, "wb") as f:
87
- f.write(audio_bytes)
 
88
  print(f"Audio file saved: {audio_path}")
89
 
90
  # STEP 4: VISUALS (Runway)
@@ -101,7 +99,7 @@ def generate_video_from_topic(topic_prompt, progress=gr.Progress(track_tqdm=True
101
  raise gr.Error(f"Runway API did not return a task UUID. Response: {post_response.json()}")
102
 
103
  video_url = None
104
- for _ in range(60):
105
  get_response = requests.get(f"{RUNWAY_API_URL}/{task_id}", headers=RUNWAY_HEADERS)
106
  status_details = get_response.json()
107
  status = status_details.get("status")
@@ -125,7 +123,8 @@ def generate_video_from_topic(topic_prompt, progress=gr.Progress(track_tqdm=True
125
  video_response = requests.get(video_url, stream=True)
126
  with open(clip_path, "wb") as f:
127
  for chunk in video_response.iter_content(chunk_size=1024):
128
- f.write(chunk)
 
129
  print(f"Video clip saved: {clip_path}")
130
 
131
  # STEP 5: STITCHING (FFmpeg)
 
1
  import gradio as gr
2
  import os
3
  import google.generativeai as genai
 
4
  from elevenlabs.client import ElevenLabs
5
  from tavily import TavilyClient
6
  import requests
 
14
  genai.configure(api_key=os.environ["GEMINI_API_KEY"])
15
  tavily_client = TavilyClient(api_key=os.environ["TAVILY_API_KEY"])
16
  RUNWAY_API_KEY = os.environ["RUNWAY_API_KEY"]
 
 
17
  elevenlabs_client = ElevenLabs(api_key=os.environ["ELEVENLABS_API_KEY"])
 
18
  except KeyError as e:
19
  raise ValueError(f"API Key Error: Please set the {e} secret in your Hugging Face Space settings.")
20
 
 
73
  audio_path = f"audio_{job_id}.mp3"
74
  intermediate_files.append(audio_path)
75
 
76
+ # !!!!!!!!!!! THIS IS THE CORRECTED LINE !!!!!!!!!!!
77
+ audio_bytes = elevenlabs_client.generate.from_text(
78
  text=narration,
79
+ voice="Adam", # You can choose any available voice
80
  model="eleven_multilingual_v2"
81
  )
82
+ # Save the audio file
83
  with open(audio_path, "wb") as f:
84
+ for chunk in audio_bytes:
85
+ f.write(chunk)
86
  print(f"Audio file saved: {audio_path}")
87
 
88
  # STEP 4: VISUALS (Runway)
 
99
  raise gr.Error(f"Runway API did not return a task UUID. Response: {post_response.json()}")
100
 
101
  video_url = None
102
+ for _ in range(60): # Poll for up to 10 minutes (60 * 10s)
103
  get_response = requests.get(f"{RUNWAY_API_URL}/{task_id}", headers=RUNWAY_HEADERS)
104
  status_details = get_response.json()
105
  status = status_details.get("status")
 
123
  video_response = requests.get(video_url, stream=True)
124
  with open(clip_path, "wb") as f:
125
  for chunk in video_response.iter_content(chunk_size=1024):
126
+ if chunk:
127
+ f.write(chunk)
128
  print(f"Video clip saved: {clip_path}")
129
 
130
  # STEP 5: STITCHING (FFmpeg)