spagestic commited on
Commit
c8f218f
·
1 Parent(s): fa5acc0

chatterbox imported

Browse files
.env.example CHANGED
@@ -3,3 +3,9 @@
3
 
4
  # Mistral AI API Key - Get yours from https://console.mistral.ai/
5
  MISTRAL_API_KEY=your_mistral_api_key_here
 
 
 
 
 
 
 
3
 
4
  # Mistral AI API Key - Get yours from https://console.mistral.ai/
5
  MISTRAL_API_KEY=your_mistral_api_key_here
6
+
7
+ HEALTH_ENDPOINT=https://your-modal-endpoint/chatterbox-health
8
+ GENERATE_AUDIO_ENDPOINT=https://your-modal-endpoint/chatterbox-generate-audio
9
+ GENERATE_JSON_ENDPOINT=https://your-modal-endpoint/chatterbox-generate-json
10
+ GENERATE_WITH_FILE_ENDPOINT=https://your-modal-endpoint/chatterbox-generate-with-file
11
+ GENERATE_ENDPOINT=https://your-modal-endpoint/chatterbox-generate
ui/chatterbox/check_api_health.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def check_api_health():
2
+ import requests
3
+ import os
4
+ HEALTH_ENDPOINT = os.getenv("HEALTH_ENDPOINT", "YOUR-MODAL-ENDPOINT-URL/health")
5
+ try:
6
+ response = requests.get(HEALTH_ENDPOINT, timeout=10)
7
+ if response.status_code == 200:
8
+ data = response.json()
9
+ return f"✅ API Status: {data.get('status', 'Unknown')} | Model Loaded: {data.get('model_loaded', False)}"
10
+ else:
11
+ return f"⚠️ API returned status code: {response.status_code}"
12
+ except Exception as e:
13
+ return f"❌ API Health Check Failed: {str(e)}"
ui/chatterbox/custom_css.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ custom_css = """
2
+ .gradio-container {
3
+ max-width: 1200px !important;
4
+ }
5
+ .status-box {
6
+ padding: 10px;
7
+ border-radius: 5px;
8
+ }
9
+ """
ui/chatterbox/generate_sample_text.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ def generate_sample_text():
2
+ import random
3
+ samples = [
4
+ "Hello! This is a test of the Chatterbox TTS system running on Modal.",
5
+ "The quick brown fox jumps over the lazy dog.",
6
+ "Welcome to the future of text-to-speech technology.",
7
+ "Now let's make my mum's favourite. So three mars bars into the pan. Then we add the tuna and just stir for a bit, just let the chocolate and fish infuse.",
8
+ "This is an example of voice cloning using artificial intelligence.",
9
+ ]
10
+ return random.choice(samples)
ui/chatterbox/generate_tts_audio.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def generate_tts_audio(text_input: str, audio_prompt_input, progress=None):
2
+ import os
3
+ import requests
4
+ import tempfile
5
+ import soundfile as sf
6
+ import numpy as np
7
+ import gradio as gr
8
+ GENERATE_AUDIO_ENDPOINT = os.getenv("GENERATE_AUDIO_ENDPOINT", "YOUR-MODAL-ENDPOINT-URL/generate_audio")
9
+ GENERATE_WITH_FILE_ENDPOINT = os.getenv("GENERATE_WITH_FILE_ENDPOINT", "YOUR-MODAL-ENDPOINT-URL/generate_with_file")
10
+ if not text_input or len(text_input.strip()) == 0:
11
+ raise gr.Error("Please enter some text to synthesize.")
12
+ if len(text_input) > 1000:
13
+ raise gr.Error("Text is too long. Maximum 1000 characters allowed.")
14
+ if progress: progress(0.1, desc="Preparing request...")
15
+ try:
16
+ if audio_prompt_input is None:
17
+ if progress: progress(0.3, desc="Sending request to API...")
18
+ payload = {"text": text_input}
19
+ response = requests.post(
20
+ GENERATE_AUDIO_ENDPOINT,
21
+ json=payload,
22
+ headers={"Content-Type": "application/json"},
23
+ timeout=60
24
+ )
25
+ if response.status_code != 200:
26
+ raise gr.Error(f"API Error: {response.status_code} - {response.text}")
27
+ if progress: progress(0.8, desc="Processing audio response...")
28
+ with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as temp_file:
29
+ temp_file.write(response.content)
30
+ temp_path = temp_file.name
31
+ audio_data, sample_rate = sf.read(temp_path)
32
+ os.unlink(temp_path)
33
+ if progress: progress(1.0, desc="Complete!")
34
+ return (sample_rate, audio_data)
35
+ else:
36
+ if progress: progress(0.3, desc="Preparing voice prompt...")
37
+ files = {'text': (None, text_input)}
38
+ with open(audio_prompt_input, 'rb') as f:
39
+ audio_content = f.read()
40
+ files['voice_prompt'] = ('voice_prompt.wav', audio_content, 'audio/wav')
41
+ if progress: progress(0.5, desc="Sending request with voice cloning...")
42
+ response = requests.post(
43
+ GENERATE_WITH_FILE_ENDPOINT,
44
+ files=files,
45
+ timeout=120
46
+ )
47
+ if response.status_code != 200:
48
+ raise gr.Error(f"API Error: {response.status_code} - {response.text}")
49
+ if progress: progress(0.8, desc="Processing cloned voice response...")
50
+ with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as temp_file:
51
+ temp_file.write(response.content)
52
+ temp_path = temp_file.name
53
+ audio_data, sample_rate = sf.read(temp_path)
54
+ os.unlink(temp_path)
55
+ if progress: progress(1.0, desc="Voice cloning complete!")
56
+ return (sample_rate, audio_data)
57
+ except requests.exceptions.Timeout:
58
+ raise gr.Error("Request timed out. The API might be under heavy load. Please try again.")
59
+ except requests.exceptions.ConnectionError:
60
+ raise gr.Error("Unable to connect to the API. Please check if the endpoint URL is correct.")
61
+ except Exception as e:
62
+ raise gr.Error(f"Error generating audio: {str(e)}")
ui/chatterbox/update_char_count.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ def update_char_count(text):
2
+ count = len(text) if text else 0
3
+ return f"{count}/1000"