on1onmangoes commited on
Commit
20ecb21
·
verified ·
1 Parent(s): b7da268

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +102 -0
app.py CHANGED
@@ -169,6 +169,108 @@ def load_sample_text(sample_index):
169
  return ""
170
 
171
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
  # Create Gradio interfacegr
173
  with gr.Blocks(
174
  title="Vui",
 
169
  return ""
170
 
171
 
172
+ #Added by on1onmangoes on 250610 to change this into mcp server
173
+
174
+ # MCP Server Functions - Add these after your existing functions
175
+ def generate_podcast_audio_mcp(text, temperature=0.5, top_k=100, max_duration=60):
176
+ """
177
+ Generate podcast-style audio from text using AI voice synthesis.
178
+
179
+ Args:
180
+ text: The podcast script or text to convert to speech
181
+ temperature: Voice variation (0.1-1.0, higher = more varied)
182
+ top_k: Top-k sampling parameter (1-200)
183
+ max_duration: Maximum audio duration in seconds
184
+
185
+ Returns:
186
+ String with audio generation status and metadata
187
+ """
188
+ if not text.strip():
189
+ return "Error: Please provide text to convert to speech"
190
+
191
+ if current_model is None:
192
+ return "Error: No voice model loaded"
193
+
194
+ try:
195
+ # Use your existing text_to_speech function
196
+ audio_result, info = text_to_speech(text, temperature, top_k, None, max_duration)
197
+
198
+ if audio_result is None:
199
+ return f"Error: {info}"
200
+
201
+ sample_rate, audio_array = audio_result
202
+ duration = len(audio_array) / sample_rate
203
+
204
+ return f"✅ Generated {duration:.1f}s of podcast audio successfully. {info}"
205
+
206
+ except Exception as e:
207
+ return f"Error generating podcast audio: {str(e)}"
208
+
209
+ def get_podcast_samples_mcp():
210
+ """
211
+ Get sample podcast texts that can be used for audio generation.
212
+
213
+ Returns:
214
+ String with formatted sample podcast scripts
215
+ """
216
+ samples_info = []
217
+ for i, sample in enumerate(SAMPLE_TEXTS):
218
+ samples_info.append(f"**Sample {i+1}:** {sample[:100]}...")
219
+
220
+ return "Available podcast samples:\n\n" + "\n\n".join(samples_info)
221
+
222
+ def get_full_podcast_sample_mcp(sample_number):
223
+ """
224
+ Get the full text of a specific podcast sample.
225
+
226
+ Args:
227
+ sample_number: Sample number (1-4)
228
+
229
+ Returns:
230
+ Full text of the requested sample
231
+ """
232
+ try:
233
+ index = int(sample_number) - 1
234
+ if 0 <= index < len(SAMPLE_TEXTS):
235
+ return f"Sample {sample_number} full text:\n\n{SAMPLE_TEXTS[index]}"
236
+ else:
237
+ return f"Error: Sample {sample_number} not found. Available samples: 1-{len(SAMPLE_TEXTS)}"
238
+ except ValueError:
239
+ return "Error: Please provide a valid sample number (1-4)"
240
+
241
+ def change_voice_model_mcp(model_name):
242
+ """
243
+ Change the active voice model for podcast generation.
244
+
245
+ Args:
246
+ model_name: Name of the voice model to load (currently only COHOST available)
247
+
248
+ Returns:
249
+ Status message indicating success or failure
250
+ """
251
+ try:
252
+ if model_name not in AVAILABLE_MODELS:
253
+ available = ", ".join(AVAILABLE_MODELS.keys())
254
+ return f"Error: Model '{model_name}' not available. Available models: {available}"
255
+
256
+ status = change_model(model_name)
257
+ return status
258
+ except Exception as e:
259
+ return f"Error changing model: {str(e)}"
260
+
261
+ def get_voice_models_info_mcp():
262
+ """
263
+ Get information about available voice models.
264
+
265
+ Returns:
266
+ String with available voice models and current model status
267
+ """
268
+ available = ", ".join(AVAILABLE_MODELS.keys())
269
+ current = current_model_name if current_model_name else "Unknown"
270
+
271
+ return f"Available voice models: {available}\nCurrently loaded: {current}"
272
+
273
+
274
  # Create Gradio interfacegr
275
  with gr.Blocks(
276
  title="Vui",