File size: 9,475 Bytes
091be4e
 
67b64d0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f3cff30
67b64d0
f3cff30
 
67b64d0
f3cff30
 
 
 
67b64d0
 
 
 
 
 
 
 
 
 
 
091be4e
 
 
 
 
 
 
 
67b64d0
091be4e
 
 
 
 
 
 
 
 
 
67b64d0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4320a47
 
 
 
 
 
 
67b64d0
 
 
 
 
 
 
 
 
 
 
 
 
 
f3cff30
 
 
 
 
 
 
091be4e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4320a47
091be4e
 
 
 
 
 
 
 
 
 
 
 
 
67b64d0
 
 
 
 
 
 
091be4e
 
 
 
67b64d0
 
 
 
 
 
 
091be4e
67b64d0
 
 
 
 
 
 
091be4e
4320a47
 
 
 
 
 
 
091be4e
67b64d0
 
 
 
 
 
 
091be4e
67b64d0
 
 
 
 
 
 
091be4e
f3cff30
 
 
 
 
 
 
 
 
 
091be4e
f3cff30
 
091be4e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67b64d0
 
 
 
 
 
f3cff30
67b64d0
091be4e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#!/usr/bin/env python3
"""
ChatterboxTTS Gradio Web Interface - Main Entry Point
====================================================

OVERVIEW:
This is the main web interface for ChatterboxTTS, providing a user-friendly
Gradio-based GUI for audiobook generation. It serves as the primary entry point
for users who prefer web interfaces over command-line tools.

ARCHITECTURE:
- MODULAR TAB SYSTEM: Each major function is a separate tab module
- GRACEFUL DEGRADATION: Missing tab modules show placeholder pages
- RESPONSIVE DESIGN: Works on desktop and mobile browsers
- IMPORT SAFETY: Handles missing dependencies gracefully

AVAILABLE TABS:
1. Convert Book (Tab 1) - FUNCTIONAL: Main TTS conversion interface
2. Configuration (Tab 2) - FUNCTIONAL: System configuration settings
3. Voice Analysis (Tab 3) - PLACEHOLDER: Voice sample analysis tools  
4. Combine Audio (Tab 4) - FUNCTIONAL: Audio file combination tools
5. Prepare Text (Tab 5) - FUNCTIONAL: Text preparation and chunking
6. Settings (Tab 6) - FUNCTIONAL: Configuration management
7. Chunk Tools (Tab 7) - FUNCTIONAL: Chunk editing and repair
8. JSON Generate (Tab 8) - FUNCTIONAL: Direct JSON-to-audiobook generation
9. Diagnostics (Tab 9) - FUNCTIONAL: Parallel processing performance diagnostics
10. System Monitor (Tab 10) - PLACEHOLDER: Performance monitoring

DEPLOYMENT MODES:
- LOCAL: python3 gradio_main_interface.py (development)
- HUGGINGFACE SPACES: Called by app.py launcher (production)
- COLAB/RUNPOD: Automatic sharing and port configuration

TECHNICAL FEATURES:
- Auto-detects HuggingFace Spaces environment
- Configurable sharing and port settings
- Error handling for missing tab modules
- Clean, professional interface design
"""

import gradio as gr
import sys
import os
from pathlib import Path

# Add the current directory to Python path for imports
# This ensures tab modules can be imported regardless of working directory
sys.path.append(str(Path(__file__).parent))

# Import tab modules
try:
    from gradio_tabs.tab1_convert_book import create_convert_book_tab
    TAB1_AVAILABLE = True
except ImportError as e:
    print(f"⚠️  Tab 1 not available: {e}")
    TAB1_AVAILABLE = False

try:
    from gradio_tabs.tab2_configuration import create_configuration_tab
    TAB2_AVAILABLE = True
except ImportError as e:
    print(f"⚠️  Tab 2 (Configuration) not available: {e}")
    TAB2_AVAILABLE = False

try:
    from gradio_tabs.tab4_combine_audio import create_combine_audio_tab
    TAB4_AVAILABLE = True
except ImportError as e:
    print(f"⚠️  Tab 4 (Combine Audio) not available: {e}")
    TAB4_AVAILABLE = False

try:
    from gradio_tabs.tab5_prepare_text import create_prepare_text_tab
    TAB5_AVAILABLE = True
except ImportError as e:
    print(f"⚠️  Tab 5 (Prepare Text) not available: {e}")
    TAB5_AVAILABLE = False

try:
    from gradio_tabs.tab6_settings import create_settings_tab_interface
    TAB6_AVAILABLE = True
except ImportError as e:
    print(f"⚠️  Tab 6 (Settings) not available: {e}")
    TAB6_AVAILABLE = False

try:
    from gradio_tabs.tab7_chunk_tools import create_chunk_tools_tab
    TAB7_AVAILABLE = True
except ImportError as e:
    print(f"⚠️  Tab 7 (Chunk Tools) not available: {e}")
    TAB7_AVAILABLE = False

try:
    from gradio_tabs.tab8_json_generate import create_json_generate_tab
    TAB8_AVAILABLE = True
except ImportError as e:
    print(f"⚠️  Tab 8 (JSON Generate) not available: {e}")
    TAB8_AVAILABLE = False

try:
    from gradio_tabs.tab_diagnostics import create_diagnostics_tab
    TAB_DIAGNOSTICS_AVAILABLE = True
except ImportError as e:
    print(f"⚠️  Diagnostics tab not available: {e}")
    TAB_DIAGNOSTICS_AVAILABLE = False

def create_placeholder_tab(tab_name, tab_number):
    """Create a placeholder tab for future implementation"""
    with gr.Column():
        gr.Markdown(f"# 🚧 {tab_name}")
        gr.Markdown(f"*Tab {tab_number} - Coming Soon*")
        gr.Markdown("This tab will be implemented in a future update.")

        gr.Button("Placeholder Button", interactive=False)

def create_main_interface():
    """Create the main ChatterboxTTS Gradio interface with all tabs"""

    with gr.Blocks(
        title="ChatterboxTTS - Complete Interface",
        theme=gr.themes.Soft(),
        css="""
        .gradio-container {
            max-width: 1200px !important;
        }
        """
    ) as demo:

        # Header
        gr.Markdown("""
        # 🎀 ChatterboxTTS - Complete Web Interface
        *Modular audiobook generation system with advanced TTS capabilities*
        """)

        # Tab interface
        with gr.Tabs():
            # Tab 1: Convert Book (Working)
            if TAB1_AVAILABLE:
                with gr.Tab("1. Convert Book"):
                    create_convert_book_tab()
            else:
                with gr.Tab("1. Convert Book"):
                    create_placeholder_tab("Convert Book", 1)

            # Tab 2: Configuration Settings (Working)
            if TAB2_AVAILABLE:
                with gr.Tab("2. Configuration"):
                    create_configuration_tab()
            else:
                with gr.Tab("2. Configuration"):
                    create_placeholder_tab("Configuration Settings", 2)

            with gr.Tab("3. Voice Analysis"):
                create_placeholder_tab("Voice Analysis", 3)

            # Tab 4: Combine Audio (Working)
            if TAB4_AVAILABLE:
                with gr.Tab("4. Combine Audio"):
                    create_combine_audio_tab()
            else:
                with gr.Tab("4. Combine Audio"):
                    create_placeholder_tab("Combine Audio", 4)

            # Tab 5: Prepare Text (Working)
            if TAB5_AVAILABLE:
                with gr.Tab("5. Prepare Text"):
                    create_prepare_text_tab()
            else:
                with gr.Tab("5. Prepare Text"):
                    create_placeholder_tab("Prepare Text", 5)

            # Tab 6: Settings (Working)
            if TAB6_AVAILABLE:
                with gr.Tab("6. Settings"):
                    create_settings_tab_interface()
            else:
                with gr.Tab("6. Settings"):
                    create_placeholder_tab("Settings", 6)

            # Tab 7: Chunk Tools (Working)
            if TAB7_AVAILABLE:
                with gr.Tab("7. Chunk Tools"):
                    create_chunk_tools_tab()
            else:
                with gr.Tab("7. Chunk Tools"):
                    create_placeholder_tab("Chunk Tools", 7)

            # Tab 8: JSON Generate (Working)
            if TAB8_AVAILABLE:
                with gr.Tab("8. JSON Generate"):
                    create_json_generate_tab()
            else:
                with gr.Tab("8. JSON Generate"):
                    create_placeholder_tab("JSON Generate", 8)

            # Tab 9: Diagnostics (Working)
            if TAB_DIAGNOSTICS_AVAILABLE:
                with gr.Tab("9. Diagnostics"):
                    create_diagnostics_tab()
            else:
                with gr.Tab("9. Diagnostics"):
                    create_placeholder_tab("System Diagnostics", 9)

            with gr.Tab("10. System Monitor"):
                create_placeholder_tab("System Monitor", 10)

            with gr.Tab("11. About"):
                create_placeholder_tab("About", 11)

        # Footer
        gr.Markdown("""
        ---
        *ChatterboxTTS Gradio Interface - Modular Design*
        Each tab is a separate module for easy maintenance and development.
        """)

    return demo

def launch_interface():
    """Launch the main interface"""
    print("πŸš€ ChatterboxTTS - Starting Main Interface")
    print("πŸ“Š Tab Status:")
    print(f"   Tab 1 (Convert Book): {'βœ… Available' if TAB1_AVAILABLE else '❌ Not Available'}")
    print(f"   Tab 2 (Configuration): {'βœ… Available' if TAB2_AVAILABLE else '❌ Not Available'}")
    print(f"   Tab 4 (Combine Audio): {'βœ… Available' if TAB4_AVAILABLE else '❌ Not Available'}")
    print(f"   Tab 5 (Prepare Text): {'βœ… Available' if TAB5_AVAILABLE else '❌ Not Available'}")
    print(f"   Tab 6 (Settings): {'βœ… Available' if TAB6_AVAILABLE else '❌ Not Available'}")
    print(f"   Tab 7 (Chunk Tools): {'βœ… Available' if TAB7_AVAILABLE else '❌ Not Available'}")
    print(f"   Tab 8 (JSON Generate): {'βœ… Available' if TAB8_AVAILABLE else '❌ Not Available'}")
    print(f"   Tab 9 (Diagnostics): {'βœ… Available' if TAB_DIAGNOSTICS_AVAILABLE else '❌ Not Available'}")
    print("   Other Tabs: 🚧 Placeholder (Coming Soon)")
    print("-" * 50)

    demo = create_main_interface()

    # Launch configuration
    launch_kwargs = {
        'server_name': '0.0.0.0',
        'server_port': 7860,
        'show_error': True,
        'quiet': False
    }

    # Detect cloud environments
    if os.getenv("RUNPOD_POD_ID"):
        print("☁️  RunPod deployment detected")
        launch_kwargs['share'] = True
    elif os.getenv("COLAB_GPU"):
        print("☁️  Google Colab detected")
        launch_kwargs['share'] = True
    else:
        print("πŸ’» Local deployment")
        launch_kwargs['share'] = False

    print(f"🌐 Interface will be available at: http://localhost:{launch_kwargs['server_port']}")

    try:
        demo.launch(**launch_kwargs)
    except Exception as e:
        print(f"❌ Error launching interface: {e}")
        raise

if __name__ == "__main__":
    launch_interface()