bluenevus commited on
Commit
896ca54
·
verified ·
1 Parent(s): 54be90e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -0
app.py CHANGED
@@ -12,6 +12,7 @@ import threading
12
  import queue
13
  import os
14
  import logging
 
15
 
16
  logging.basicConfig(level=logging.INFO)
17
  logger = logging.getLogger(__name__)
@@ -31,6 +32,7 @@ print(f"Using device: {device}")
31
  model = None
32
  tokenizer = None
33
 
 
34
  def load_model():
35
  global model, tokenizer
36
 
@@ -137,6 +139,7 @@ def generate_podcast_script(api_key, content, duration, num_hosts):
137
  clean_text = re.sub(r'[^a-zA-Z0-9\s.,?!<>]', '', response.text)
138
  return clean_text
139
 
 
140
  def text_to_speech(text, voice):
141
  global model, tokenizer
142
  if tokenizer is None or model is None:
@@ -153,6 +156,7 @@ def mel_to_audio(mel):
153
  # Placeholder implementation
154
  return np.zeros(24000, dtype=np.float32) # 1 second of silence
155
 
 
156
  def process_audio_segment(line, voice, result_queue):
157
  try:
158
  audio = text_to_speech(line, voice)
@@ -161,6 +165,7 @@ def process_audio_segment(line, voice, result_queue):
161
  logger.error(f"Error processing audio segment: {str(e)}")
162
  result_queue.put(None)
163
 
 
164
  def render_podcast(api_key, script, voice1, voice2, num_hosts):
165
  lines = [line for line in script.split('\n') if line.strip()]
166
  audio_segments = []
 
12
  import queue
13
  import os
14
  import logging
15
+ import spaces
16
 
17
  logging.basicConfig(level=logging.INFO)
18
  logger = logging.getLogger(__name__)
 
32
  model = None
33
  tokenizer = None
34
 
35
+ @spaces.GPU()
36
  def load_model():
37
  global model, tokenizer
38
 
 
139
  clean_text = re.sub(r'[^a-zA-Z0-9\s.,?!<>]', '', response.text)
140
  return clean_text
141
 
142
+ @spaces.GPU()
143
  def text_to_speech(text, voice):
144
  global model, tokenizer
145
  if tokenizer is None or model is None:
 
156
  # Placeholder implementation
157
  return np.zeros(24000, dtype=np.float32) # 1 second of silence
158
 
159
+ @spaces.GPU()
160
  def process_audio_segment(line, voice, result_queue):
161
  try:
162
  audio = text_to_speech(line, voice)
 
165
  logger.error(f"Error processing audio segment: {str(e)}")
166
  result_queue.put(None)
167
 
168
+ @spaces.GPU()
169
  def render_podcast(api_key, script, voice1, voice2, num_hosts):
170
  lines = [line for line in script.split('\n') if line.strip()]
171
  audio_segments = []