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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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
import gradio as gr
import os
import csv
import numpy as np
import scipy.io.wavfile as wavfile


css = """
.gradio-container input::placeholder,
.gradio-container textarea::placeholder {
    color: #333333 !important;
}

code {
    background-color: #ffde9f;
    padding: 2px 4px;
    border-radius: 3px;
}

#settings-accordion summary {
    justify-content: center;
}

.examples-holder > .label {
    color: #b45309 !important;
    font-weight: 600;
}
"""



def load_examples(csv_path):
    examples = []
    
    if not os.path.exists(csv_path):
        print(f"Warning: Examples file not found at {csv_path}")
        return examples
    
    try:
        with open(csv_path, 'r', encoding='utf-8') as f:
            reader = csv.reader(f, delimiter='|')
            for row in reader:
                if len(row) >= 2:
                    text = row[0].strip()
                    audio_path = row[1].strip()
                    
                    # Handle temperature (third column)
                    temperature = 0.7  # Default temperature
                    if len(row) >= 3:
                        try:
                            temp_str = row[2].strip()
                            if temp_str and temp_str.lower() != 'none':
                                temperature = float(temp_str)
                                # Clamp temperature to valid range
                                temperature = max(0.0, min(1.3, temperature))
                        except (ValueError, TypeError):
                            print(f"Warning: Invalid temperature value '{row[2]}', using default 0.7")
                            temperature = 0.7
                    
                    # Handle chained longform (fourth column)
                    use_chained = False  # Default to False
                    if len(row) >= 4:
                        chained_str = row[3].strip().lower()
                        if chained_str in ['true', '1', 'yes', 'on']:
                            use_chained = True
                        elif chained_str in ['false', '0', 'no', 'off', 'none', '']:
                            use_chained = False
                        else:
                            print(f"Warning: Invalid chained longform value '{row[3]}', using default False")
                            use_chained = False
                    
                    # Handle pre-generated audio path (fifth column)
                    pregenerated_audio = None
                    if len(row) >= 5:
                        pregenerated_path = row[4].strip()
                        if pregenerated_path and pregenerated_path.lower() != "none":
                            if not os.path.isabs(pregenerated_path):
                                base_dir = os.path.dirname(csv_path)
                                pregenerated_path = os.path.join(base_dir, pregenerated_path)
                            if os.path.exists(pregenerated_path):
                                pregenerated_audio = pregenerated_path
                                print(f"Found pre-generated audio: {pregenerated_path}")
                            else:
                                print(f"Warning: Pre-generated audio file not found: {pregenerated_path}")
                    
                    if audio_path.lower() == "none":
                        audio_path = None
                    elif audio_path and not os.path.isabs(audio_path):
                        base_dir = os.path.dirname(csv_path)
                        audio_path = os.path.join(base_dir, audio_path)
                        if not os.path.exists(audio_path):
                            print(f"Warning: Audio file not found: {audio_path}")
                            audio_path = None
                    
                    examples.append([text, audio_path, temperature, use_chained, pregenerated_audio])
                    print(f"Added example {len(examples)}: text={text[:30]}..., pregenerated={pregenerated_audio}")
    except Exception as e:
        print(f"Error loading examples: {e}")
    
    return examples

def run_generation_pipeline_client(*args):
    # Demo is closed - return error message
    return None, "Status: デモは終了しました。生成例をご覧ください。/ Demo has been closed. Please check the pre-generated examples."





# Load examples
examples_csv_path = "./samples.csv"  # Adjust path as needed for client side
example_list = load_examples(examples_csv_path)
# Prepare examples for gr.Examples - only first 4 columns for input
example_inputs = [ex[:4] for ex in example_list]

# Create Gradio interface
with gr.Blocks(theme="Respair/Shiki@9.1.0", css=css) as demo:
    gr.Markdown('<h1 style="text-align: center; width: 100%; display: block;">🌸 Takane</h1>')
    
    with gr.Tabs() as tabs:
        # Notice tab (default first tab)
        with gr.TabItem("お知らせ", id=0):
            gr.HTML("""
    <div style="background-color: rgba(255, 255, 255, 0.025); padding: 30px; border-radius: 12px; backdrop-filter: blur(10px); max-width: 100%; box-shadow: 0 4px 6px rgba(0,0,0,0.1);">
        
        <h2 style="color: #000000; margin-bottom: 20px; font-size: 28px;">お知らせ</h2>
        
        <p style="color: #1a1a1a; font-weight: 500; line-height: 1.8; margin-bottom: 20px; font-size: 16px;">
         この短い間に、多くの方に『高音』を試してくださり、大変光栄に思います!<br>
         残念ながらこのデモは、数万人が利用するような実際の製品ではなく、あくまで技術的に何が可能かを示すためのものです。サーバーへの大きな負担、そして声優の方々への潜在的な悪用(話者IDがマッピングされているらしい?)を防ぐため、今はデモを停止することにしました。
        </p>
        
        <p style="color: #1a1a1a; font-weight: 500; line-height: 1.8; margin-bottom: 20px; font-size: 16px;">
        Read Meタブでも記載した通り、モデル自体を公開したり、倫理的な理由によりAPIを販売する予定もありません。ただし、日本でこの分野を前進させるために、必要な支援やパートナーを見つけられればと願っています。音声合成に限らず、私が本当に楽しんでいる分野ですので、もしどなたかご存知でしたら、ぜひお声がけください!
        </p>
        
        <p style="color: #1a1a1a; font-weight: 500; line-height: 1.8; margin-bottom: 20px; font-size: 16px;">
        ご理解いただき、ありがとうございます。楽しんでいただけていれば幸いです。
        </p>
        
        <p style="color: #1a1a1a; font-weight: 500; line-height: 1.8; margin-bottom: 20px; font-size: 16px;">
        もし私の活動や音声・ASR etc. などと言うフィールドにご興味があれば、今後もまた何か楽しいことをするかもしれませんので、<a href="https://x.com/MystiqCaleid" target="_blank" style="color: #1d4ed8; text-decoration: underline;">Twitter | X</a>でフォローしていただけると嬉しいです!
        </p>
        
        <p style="color: #1a1a1a; font-weight: 500; line-height: 1.8; margin-bottom: 20px; font-size: 16px;">
        デモをテストできなかった方は、ぜひExamplesタブで生成済みの例をご覧ください。(サンプル自体をクリックすると、事前に生成された例がメインタブに読み込まれます。)
        </p>
        
        <div style="margin-top: 40px; padding-top: 20px; border-top: 1px solid rgba(0,0,0,0.1);">
            <p style="color: #666; font-size: 14px; text-align: center;">
                🌸 Well boys, party is over!
            </p>
        </div>
        
    </div>
    """)
        
        with gr.TabItem("Speech Generation"):
            with gr.Row():
                with gr.Column(scale=2):
                    text_input = gr.Textbox(
                        label="Text to Synthesize", 
                        lines=5, 
                        value="<spk_1146> はいはい、それでは、チャンネル登録よろしくお願いしまーす。じゃあみんな、また明日ねー、ばいばーい。"
                    )
                    
                    # Settings and Generate button
                    with gr.Row(equal_height=False):
                        with gr.Accordion("----------------------------------⭐ 🛠️ ⭐", open=False, label="_"):
                            turbo_checkbox = gr.Checkbox(
                                label="⚡ Turbo Mode (Fast generation, single candidate)", 
                                value=False
                            )
                            num_candidates_slider = gr.Slider(
                                label="Number of Candidates", 
                                minimum=1, 
                                maximum=10, 
                                value=5, 
                                step=1
                            )
                            cfg_scale_slider = gr.Slider(
                                label="CFG Scale", 
                                minimum=1.0, 
                                maximum=3.0, 
                                value=1.4, 
                                step=0.1
                            )
                            top_k_slider = gr.Slider(
                                label="Top K", 
                                minimum=10, 
                                maximum=100, 
                                value=55, 
                                step=5
                            )
                            temperature_slider = gr.Slider(
                                label="Temperature (below 0.6 can break)", 
                                minimum=0.0, 
                                maximum=1.3, 
                                value=0.7, 
                                step=0.1
                            )
                            seed_slider = gr.Slider(
                                label="Seed (use -1 for random)", 
                                minimum=-1, 
                                maximum=2700000000, 
                                value=2687110803, 
                                step=1
                            )
                            chained_longform_checkbox = gr.Checkbox(
                                label="Use Chained Longform (Sequential conditioning for consistency)", 
                                value=False
                            )
                            audio_prompt_input = gr.Audio(
                                label="Audio Prompt (Optional - オプション) [Max 10 seconds / 最大10秒]",
                                sources=["upload", "microphone"],
                                type="numpy"
                            )
                            
                            # Turbo mode event handler
                            def toggle_turbo(turbo_enabled):
                                if turbo_enabled:
                                    return 1, 1.0  # num_candidates=1, temperature=1.0
                                else:
                                    return 5, 0.7  # default values
                            
                            turbo_checkbox.change(
                                fn=toggle_turbo,
                                inputs=[turbo_checkbox],
                                outputs=[num_candidates_slider, temperature_slider]
                            )
                        
                        with gr.Column(scale=1):
                            generate_button = gr.Button("Generate", variant="primary")
                   
                with gr.Column(scale=1):
                    status_output = gr.Textbox(label="Status", interactive=False)
                    audio_output = gr.Audio(label="Generated Speech", interactive=False, show_download_button=True)
                    
            # Event handler
            generate_button.click(
                fn=run_generation_pipeline_client,
                inputs=[
                    text_input,
                    audio_prompt_input,
                    num_candidates_slider,
                    cfg_scale_slider,
                    top_k_slider,
                    temperature_slider,
                    chained_longform_checkbox,
                    seed_slider
                ],
                outputs=[audio_output, status_output],
                concurrency_limit=4  # Limit concurrent requests
            )
        
        with gr.TabItem("Examples"):
            if example_list:
                gr.Markdown("### Sample Text and Audio Prompts")
                gr.Markdown("Click on any example below to load it into the Speech Generation tab")
                gr.Markdown("*Note: Pre-generated audio will be loaded automatically*")
                
                # Function to load example with pre-generated audio
                def load_example_fn(text, audio, temp, chained):
                    """Load example and its pre-generated audio"""
                    # Find the matching example in the full list
                    for ex in example_list:
                        if ex[0] == text:  # Match on text since it's unique
                            pregenerated_path = ex[4] if len(ex) > 4 else None
                            
                            if pregenerated_path and os.path.exists(pregenerated_path):
                                try:
                                    sample_rate, audio_data = wavfile.read(pregenerated_path)
                                    status = "Status: Pre-generated example loaded / 生成済みの例を読み込みました"
                                    return text, audio, temp, chained, (sample_rate, audio_data), status
                                except Exception as e:
                                    return text, audio, temp, chained, None, f"Status: Error loading audio: {str(e)}"
                            else:
                                return text, audio, temp, chained, None, "Status: No pre-generated audio available"
                    
                    return text, audio, temp, chained, None, "Status: Example loaded"
                
                gr.Examples(
                    examples=example_inputs,
                    inputs=[text_input, audio_prompt_input, temperature_slider, chained_longform_checkbox],
                    outputs=[text_input, audio_prompt_input, temperature_slider, chained_longform_checkbox, audio_output, status_output],
                    fn=load_example_fn,
                    label="Click to load an example",
                    cache_examples=False,
                    run_on_click=True
                )
            else:
                gr.Markdown("### No examples available")
                gr.Markdown("Examples will appear here when they are configured.")
       
        with gr.TabItem("Read Me"):
            gr.HTML("""
    <div style="background-color: rgba(255, 255, 255, 0.025); padding: 30px; border-radius: 12px; backdrop-filter: blur(10px); max-width: 100%; box-shadow: 0 4px 6px rgba(0,0,0,0.1);">
        
        <h2 style="color: #000000; margin-bottom: 20px; font-size: 28px;">About Takane</h2>
        
        <p style="color: #1a1a1a; font-weight: 500; line-height: 1.8; margin-bottom: 20px; font-size: 16px;">
        Takane is a frontier Japanese-only speech synthesis network that was trained on tens of thousands of high quality data to autoregressively generate highly compressed audio codes.
        This network is powered by Kanadec, the world's only 44.1 kHz - 25 frame rate speech tokenizer which utilizes semantic and acoustic distillation to generate audio tokens as fast as possible.
        </p>
        
        <p style="color: #1a1a1a; font-weight: 500; line-height: 1.8; margin-bottom: 20px; font-size: 16px;">
        There are two checkpoints in this demo, one of them utilizes a custom version of Rope to manipulate duration which is seldom seen in autoregressive settings. Please treat it as a proof of concept as its outputs are not very reliable. I'll include it to show that it can work to some levels and can be expanded upon.
        Both checkpoints have been fine-tuned on a subset of the dataset with only speaker tags. This will allow us to generate high quality samples without relying on audio prompts or dealing with random speaker attributes, but at the cost of tanking the zero-shot faithfulness of the model.
        </p>
        
        <p style="color: #1a1a1a; font-weight: 500; line-height: 1.8; margin-bottom: 20px; font-size: 16px;">
        Takane also comes with an Anti-Hallucination Algorithm (AHA) that generates a few candidates in parallel and automatically returns the best one at the cost of introducing a small overhead. 
        If you need the fastest response time possible, feel free to enable the Turbo mode. It will disable AHA and tweak the parameters internally to produce samples as fast as 2-3 seconds (though due to an influx of users coming in, you probably will be qeued and have to wait!)
        </p>
        
        <p style="color: #1a1a1a; font-weight: 500; line-height: 1.8; margin-bottom: 20px; font-size: 16px;">
        There's no plan to release this model or even monetize it. this is just a tech demo, therefore I am not accountable for what users may generate.
        </p>

        <p style="color: #1a1a1a; font-weight: 500; line-height: 1.8; margin-bottom: 20px; font-size: 16px;">
        If you're not using an audio prompt or a speaker tag, or even if you do, you find the later sentences to be too different, then in that case you may want to enable the <code>Chained mode</code>, which will sequentially condition each output to ensure speaker consistency.
        </p>
        
        <h3 style="color: #000000; margin-top: 30px; margin-bottom: 15px; font-size: 20px;">Summary of Technical Properties:</h3>
        <ul style="color: #1a1a1a; font-weight: 500; line-height: 1.8; font-size: 15px;">
            <li style="margin: 8px 0;">Encoder-Decoder fully autoregressive Transformer</li>
            <li style="margin: 8px 0;">Powered by Kanadec (44.1 kHz - 25 codes per second)</li>
            <li style="margin: 8px 0;">500M parameters</li>
            <li style="margin: 8px 0;">Tens of thousands of anime-esque data, everyday regular Japanese is not supported</li>
            <li style="margin: 8px 0;">Experimental support for duration-controllable synthesis</li>
        </ul>
        
        <div style="margin-top: 40px; padding-top: 20px; border-top: 1px solid rgba(0,0,0,0.1);">
            <p style="color: #666; font-size: 14px; text-align: center;">
                🌸 Takane - Advanced Japanese Text-to-Speech System
            </p>
        </div>
        
    </div>
    """)
           
if __name__ == "__main__":
    demo.queue(api_open=False, max_size=15).launch(show_api=False, share=True)