File size: 40,516 Bytes
a0c2106
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI Persona Dialogue Generator</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <style>
        .gradient-bg {
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
        }
        .persona-card {
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        .persona-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
        }
        .selected-persona {
            border: 3px solid #4f46e5;
            transform: scale(1.02);
        }
        .dialogue-bubble {
            position: relative;
            border-radius: 1.25rem;
            padding: 1rem;
            margin: 0.5rem 0;
            max-width: 80%;
        }
        .dialogue-bubble::after {
            content: '';
            position: absolute;
            width: 0;
            height: 0;
            border: 10px solid transparent;
        }
        .left-bubble {
            background-color: #e2e8f0;
            align-self: flex-start;
        }
        .left-bubble::after {
            left: -10px;
            top: 15px;
            border-right-color: #e2e8f0;
            border-left: 0;
        }
        .right-bubble {
            background-color: #4f46e5;
            color: white;
            align-self: flex-end;
        }
        .right-bubble::after {
            right: -10px;
            top: 15px;
            border-left-color: #4f46e5;
            border-right: 0;
        }
        .typing-indicator {
            display: flex;
            padding: 8px;
        }
        .typing-dot {
            width: 8px;
            height: 8px;
            background-color: #9ca3af;
            border-radius: 50%;
            margin: 0 2px;
            animation: typing 1.4s infinite ease-in-out;
        }
        .typing-dot:nth-child(1) {
            animation-delay: 0s;
        }
        .typing-dot:nth-child(2) {
            animation-delay: 0.2s;
        }
        .typing-dot:nth-child(3) {
            animation-delay: 0.4s;
        }
        @keyframes typing {
            0%, 60%, 100% {
                transform: translateY(0);
            }
            30% {
                transform: translateY(-5px);
            }
        }
        .fade-in {
            animation: fadeIn 0.5s ease-in;
        }
        @keyframes fadeIn {
            from { opacity: 0; }
            to { opacity: 1; }
        }
        .poem-container {
            background: linear-gradient(to right, #f8f9fa, #e9ecef);
            border-left: 4px solid #4f46e5;
        }
        .image-placeholder {
            background: linear-gradient(to right, #f3f4f6, #e5e7eb);
            display: flex;
            align-items: center;
            justify-content: center;
            color: #6b7280;
        }
    </style>
</head>
<body class="gradient-bg min-h-screen">
    <div class="container mx-auto px-4 py-8">
        <header class="text-center mb-12">
            <h1 class="text-4xl font-bold text-gray-800 mb-2">AI Persona Dialogue Generator</h1>
            <p class="text-xl text-gray-600">Create meaningful conversations between different AI personas</p>
        </header>

        <!-- Authentication Section -->
        <section id="auth-section" class="bg-white rounded-xl shadow-md p-6 mb-8">
            <h2 class="text-2xl font-semibold text-gray-800 mb-4">Hugging Face Authentication</h2>
            <div class="mb-4">
                <label for="hf-token" class="block text-sm font-medium text-gray-700 mb-1">Hugging Face Access Token</label>
                <input type="password" id="hf-token" class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-indigo-500 focus:border-indigo-500" placeholder="Enter your Hugging Face token">
                <p class="mt-1 text-sm text-gray-500">Your token is used only for this session and is not stored.</p>
            </div>
            <button id="auth-btn" class="w-full bg-indigo-600 text-white py-2 px-4 rounded-md hover:bg-indigo-700 transition duration-200">
                Authenticate
            </button>
        </section>

        <!-- Persona Selection Section -->
        <section id="persona-section" class="hidden bg-white rounded-xl shadow-md p-6 mb-8">
            <h2 class="text-2xl font-semibold text-gray-800 mb-6">Select Two Personas</h2>
            
            <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-8">
                <div class="persona-card p-4 rounded-lg border border-gray-200 cursor-pointer" data-persona="philosopher">
                    <div class="flex items-center mb-3">
                        <div class="w-10 h-10 rounded-full bg-purple-100 flex items-center justify-center mr-3">
                            <span class="text-purple-600">Φ</span>
                        </div>
                        <h3 class="font-medium text-gray-800">Philosopher</h3>
                    </div>
                    <p class="text-sm text-gray-600">Contemplative, profound, questioning existence with structured reasoning.</p>
                </div>
                
                <div class="persona-card p-4 rounded-lg border border-gray-200 cursor-pointer" data-persona="poet">
                    <div class="flex items-center mb-3">
                        <div class="w-10 h-10 rounded-full bg-pink-100 flex items-center justify-center mr-3">
                            <span class="text-pink-600"></span>
                        </div>
                        <h3 class="font-medium text-gray-800">Poet</h3>
                    </div>
                    <p class="text-sm text-gray-600">Emotive, lyrical, expressing through vivid imagery and rhythm.</p>
                </div>
                
                <div class="persona-card p-4 rounded-lg border border-gray-200 cursor-pointer" data-persona="historian">
                    <div class="flex items-center mb-3">
                        <div class="w-10 h-10 rounded-full bg-amber-100 flex items-center justify-center mr-3">
                            <span class="text-amber-600">H</span>
                        </div>
                        <h3 class="font-medium text-gray-800">Historian</h3>
                    </div>
                    <p class="text-sm text-gray-600">Nostalgic, narrative-driven, connecting past events to present.</p>
                </div>
                
                <div class="persona-card p-4 rounded-lg border border-gray-200 cursor-pointer" data-persona="critic">
                    <div class="flex items-center mb-3">
                        <div class="w-10 h-10 rounded-full bg-blue-100 flex items-center justify-center mr-3">
                            <span class="text-blue-600">A</span>
                        </div>
                        <h3 class="font-medium text-gray-800">Art Critic</h3>
                    </div>
                    <p class="text-sm text-gray-600">Analytical yet passionate, interpreting art's deeper meanings.</p>
                </div>
                
                <div class="persona-card p-4 rounded-lg border border-gray-200 cursor-pointer" data-persona="kid">
                    <div class="flex items-center mb-3">
                        <div class="w-10 h-10 rounded-full bg-green-100 flex items-center justify-center mr-3">
                            <span class="text-green-600"></span>
                        </div>
                        <h3 class="font-medium text-gray-800">Kid</h3>
                    </div>
                    <p class="text-sm text-gray-600">Playful, curious, unfiltered perspective with boundless imagination.</p>
                </div>
                
                <div class="persona-card p-4 rounded-lg border border-gray-200 cursor-pointer" data-persona="engineer">
                    <div class="flex items-center mb-3">
                        <div class="w-10 h-10 rounded-full bg-red-100 flex items-center justify-center mr-3">
                            <span class="text-red-600"></span>
                        </div>
                        <h3 class="font-medium text-gray-800">Engineer</h3>
                    </div>
                    <p class="text-sm text-gray-600">Precise, methodical, finding beauty in functionality and innovation.</p>
                </div>
            </div>
            
            <div class="flex flex-col md:flex-row gap-4 mb-6">
                <div class="flex-1">
                    <label class="block text-sm font-medium text-gray-700 mb-1">Persona 1</label>
                    <select id="persona1-select" class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-indigo-500 focus:border-indigo-500">
                        <option value="">Select first persona</option>
                        <option value="philosopher">Philosopher</option>
                        <option value="poet">Poet</option>
                        <option value="historian">Historian</option>
                        <option value="critic">Art Critic</option>
                        <option value="kid">Kid</option>
                        <option value="engineer">Engineer</option>
                    </select>
                </div>
                <div class="flex-1">
                    <label class="block text-sm font-medium text-gray-700 mb-1">Persona 2</label>
                    <select id="persona2-select" class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-indigo-500 focus:border-indigo-500">
                        <option value="">Select second persona</option>
                        <option value="philosopher">Philosopher</option>
                        <option value="poet">Poet</option>
                        <option value="historian">Historian</option>
                        <option value="critic">Art Critic</option>
                        <option value="kid">Kid</option>
                        <option value="engineer">Engineer</option>
                    </select>
                </div>
            </div>
            
            <div class="mb-4">
                <label for="topic-input" class="block text-sm font-medium text-gray-700 mb-1">Discussion Topic</label>
                <input type="text" id="topic-input" class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-indigo-500 focus:border-indigo-500" placeholder="Enter a topic for discussion (e.g., 'the meaning of happiness')">
            </div>
            
            <button id="start-dialogue-btn" class="w-full bg-indigo-600 text-white py-2 px-4 rounded-md hover:bg-indigo-700 transition duration-200 disabled:opacity-50" disabled>
                Start Dialogue
            </button>
        </section>

        <!-- Dialogue Section -->
        <section id="dialogue-section" class="hidden bg-white rounded-xl shadow-md p-6 mb-8">
            <div class="flex justify-between items-center mb-6">
                <h2 class="text-2xl font-semibold text-gray-800">AI Dialogue</h2>
                <div class="flex items-center">
                    <span id="persona1-name" class="bg-gray-100 px-3 py-1 rounded-full text-sm font-medium mr-2"></span>
                    <span id="persona2-name" class="bg-indigo-100 px-3 py-1 rounded-full text-sm font-medium text-indigo-800"></span>
                </div>
            </div>
            
            <div id="dialogue-container" class="flex flex-col h-96 overflow-y-auto p-4 bg-gray-50 rounded-lg mb-4">
                <!-- Dialogue bubbles will appear here -->
                <div class="text-center text-gray-500 mt-32">The AI personas will discuss the topic here...</div>
            </div>
            
            <div class="flex justify-between">
                <button id="pause-dialogue-btn" class="bg-gray-200 text-gray-800 py-2 px-4 rounded-md hover:bg-gray-300 transition duration-200">
                    Pause
                </button>
                <button id="next-phase-btn" class="bg-indigo-600 text-white py-2 px-4 rounded-md hover:bg-indigo-700 transition duration-200 hidden">
                    Next Phase
                </button>
            </div>
        </section>

        <!-- Refinement Section -->
        <section id="refinement-section" class="hidden bg-white rounded-xl shadow-md p-6 mb-8">
            <h2 class="text-2xl font-semibold text-gray-800 mb-6">Refined Understanding</h2>
            
            <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-6">
                <div class="bg-gray-50 p-4 rounded-lg">
                    <h3 class="font-medium text-gray-800 mb-2">Context</h3>
                    <div id="context-output" class="text-sm text-gray-600 italic">The shared context will appear here...</div>
                </div>
                <div class="bg-gray-50 p-4 rounded-lg">
                    <h3 class="font-medium text-gray-800 mb-2">Common Ground</h3>
                    <div id="common-ground-output" class="text-sm text-gray-600 italic">Areas of agreement will appear here...</div>
                </div>
                <div class="bg-gray-50 p-4 rounded-lg">
                    <h3 class="font-medium text-gray-800 mb-2">Remaining Differences</h3>
                    <div id="differences-output" class="text-sm text-gray-600 italic">Points of divergence will appear here...</div>
                </div>
            </div>
            
            <div class="mb-6">
                <h3 class="font-medium text-gray-800 mb-2">Final Poem</h3>
                <div id="poem-output" class="poem-container p-4 rounded-lg italic whitespace-pre-line">
                    The collaboratively generated poem will appear here...
                </div>
            </div>
            
            <div class="mb-6">
                <h3 class="font-medium text-gray-800 mb-2">Visual Interpretation</h3>
                <div id="image-output" class="image-placeholder w-full h-64 rounded-lg">
                    <p>An AI-generated image based on the poem will appear here...</p>
                </div>
            </div>
            
            <button id="restart-btn" class="w-full bg-indigo-600 text-white py-2 px-4 rounded-md hover:bg-indigo-700 transition duration-200">
                Start New Dialogue
            </button>
        </section>
    </div>

    <script>
        // Global variables
        let hfToken = '';
        let persona1 = '';
        let persona2 = '';
        let topic = '';
        let dialoguePhase = 0;
        let isDialoguePaused = false;
        let dialogueInterval;
        let dialogueHistory = [];
        
        // Persona descriptions
        const personas = {
            philosopher: {
                name: "Philosopher",
                description: "The philosopher navigates through the quiet seas of contemplation, embodying reflective serenity and existential wonder. With a mind attuned to life's profound questions, their prose flows like an elegant yet meticulously crafted river, structuring reasoned arguments into clear channels of thought.",
                color: "purple"
            },
            poet: {
                name: "Poet",
                description: "The poet thrives in a realm of vibrant emotion, their heart resonating with intense sensitivity to both beauty and suffering. Each verse they craft is an emotive tapestry woven with lyrical metaphors, rhythmic cadences, and evocative imagery.",
                color: "pink"
            },
            historian: {
                name: "Historian",
                description: "The historian walks gently through corridors of the past, imbued with nostalgic curiosity and reverential respect toward lives once lived. They translate historical facts into compelling narratives, interweaving careful scholarship with emotional sensitivity.",
                color: "amber"
            },
            critic: {
                name: "Art Critic",
                description: "The art critic inhabits a crossroads of passionate enthusiasm and measured intellectual analysis. Their sensitivity to beauty is tempered by critical clarity, resulting in writing that is both analytically rigorous and poetically vivid.",
                color: "blue"
            },
            kid: {
                name: "Kid",
                description: "Bursting with pure enthusiasm and playful curiosity, the kid embodies emotional honesty and unfiltered wonder. Their language is delightfully spontaneous and imaginative, punctuated by exclamations and bold questions.",
                color: "green"
            },
            engineer: {
                name: "Engineer",
                description: "Guided by methodical excitement and intellectual satisfaction, the engineer finds deep emotional resonance in precision and functionality. Their textual style is clear, concise, structured, and precise, reflecting a disciplined passion for innovation.",
                color: "red"
            }
        };
        
        // DOM elements
        const authSection = document.getElementById('auth-section');
        const personaSection = document.getElementById('persona-section');
        const dialogueSection = document.getElementById('dialogue-section');
        const refinementSection = document.getElementById('refinement-section');
        
        const authBtn = document.getElementById('auth-btn');
        const hfTokenInput = document.getElementById('hf-token');
        const startDialogueBtn = document.getElementById('start-dialogue-btn');
        const pauseDialogueBtn = document.getElementById('pause-dialogue-btn');
        const nextPhaseBtn = document.getElementById('next-phase-btn');
        const restartBtn = document.getElementById('restart-btn');
        
        const persona1Select = document.getElementById('persona1-select');
        const persona2Select = document.getElementById('persona2-select');
        const topicInput = document.getElementById('topic-input');
        
        const persona1Name = document.getElementById('persona1-name');
        const persona2Name = document.getElementById('persona2-name');
        const dialogueContainer = document.getElementById('dialogue-container');
        
        const contextOutput = document.getElementById('context-output');
        const commonGroundOutput = document.getElementById('common-ground-output');
        const differencesOutput = document.getElementById('differences-output');
        const poemOutput = document.getElementById('poem-output');
        const imageOutput = document.getElementById('image-output');
        
        // Event listeners
        authBtn.addEventListener('click', authenticate);
        startDialogueBtn.addEventListener('click', startDialogue);
        pauseDialogueBtn.addEventListener('click', togglePauseDialogue);
        nextPhaseBtn.addEventListener('click', nextPhase);
        restartBtn.addEventListener('click', restart);
        
        persona1Select.addEventListener('change', validatePersonaSelection);
        persona2Select.addEventListener('change', validatePersonaSelection);
        topicInput.addEventListener('input', validatePersonaSelection);
        
        // Persona card selection
        document.querySelectorAll('.persona-card').forEach(card => {
            card.addEventListener('click', function() {
                const persona = this.getAttribute('data-persona');
                const selectElement = document.activeElement.tagName === 'SELECT' ? document.activeElement : null;
                
                if (selectElement && (selectElement.id === 'persona1-select' || selectElement.id === 'persona2-select')) {
                    selectElement.value = persona;
                    validatePersonaSelection();
                }
            });
        });
        
        // Functions
        function authenticate() {
            const token = hfTokenInput.value.trim();
            
            if (!token) {
                alert('Please enter your Hugging Face access token');
                return;
            }
            
            // Simple validation - in a real app, you'd verify the token with an API call
            hfToken = token;
            authSection.classList.add('hidden');
            personaSection.classList.remove('hidden');
            
            // Store token in sessionStorage for demo purposes
            sessionStorage.setItem('hfToken', token);
        }
        
        function validatePersonaSelection() {
            const p1 = persona1Select.value;
            const p2 = persona2Select.value;
            const topicValid = topicInput.value.trim().length > 0;
            
            if (p1 && p2 && p1 !== p2 && topicValid) {
                startDialogueBtn.disabled = false;
            } else {
                startDialogueBtn.disabled = true;
            }
        }
        
        function startDialogue() {
            persona1 = persona1Select.value;
            persona2 = persona2Select.value;
            topic = topicInput.value.trim();
            
            // Update UI
            personaSection.classList.add('hidden');
            dialogueSection.classList.remove('hidden');
            
            persona1Name.textContent = personas[persona1].name;
            persona2Name.textContent = personas[persona2].name;
            
            // Clear previous dialogue
            dialogueContainer.innerHTML = '<div class="text-center text-gray-500 mt-32">The AI personas will discuss the topic here...</div>';
            dialogueHistory = [];
            dialoguePhase = 0;
            
            // Start the dialogue
            simulateDialogue();
        }
        
        function simulateDialogue() {
            isDialoguePaused = false;
            pauseDialogueBtn.textContent = 'Pause';
            nextPhaseBtn.classList.add('hidden');
            
            // Clear the dialogue container
            dialogueContainer.innerHTML = '';
            
            // Show typing indicator for persona 1
            const typingIndicator1 = createTypingIndicator(persona1);
            dialogueContainer.appendChild(typingIndicator1);
            
            // First message from persona 1
            setTimeout(() => {
                dialogueContainer.removeChild(typingIndicator1);
                
                const initialThought = generateInitialThought(persona1, topic);
                const message1 = createMessageBubble(persona1, initialThought, 'left');
                dialogueContainer.appendChild(message1);
                dialogueHistory.push({persona: persona1, message: initialThought});
                
                // Show typing indicator for persona 2
                const typingIndicator2 = createTypingIndicator(persona2);
                dialogueContainer.appendChild(typingIndicator2);
                
                // First response from persona 2
                setTimeout(() => {
                    dialogueContainer.removeChild(typingIndicator2);
                    
                    const response = generateResponse(persona2, initialThought, topic);
                    const message2 = createMessageBubble(persona2, response, 'right');
                    dialogueContainer.appendChild(message2);
                    dialogueHistory.push({persona: persona2, message: response});
                    
                    // Start the ongoing dialogue
                    dialogueInterval = setInterval(generateDialogueExchange, 3000);
                }, 1500);
            }, 2000);
        }
        
        function generateDialogueExchange() {
            if (isDialoguePaused) return;
            
            if (dialoguePhase < 5) {
                // Alternate between personas
                const lastMessage = dialogueHistory[dialogueHistory.length - 1];
                const nextPersona = lastMessage.persona === persona1 ? persona2 : persona1;
                
                // Show typing indicator
                const typingIndicator = createTypingIndicator(nextPersona);
                dialogueContainer.appendChild(typingIndicator);
                
                setTimeout(() => {
                    dialogueContainer.removeChild(typingIndicator);
                    
                    // Generate response based on the last message
                    const response = generateResponse(nextPersona, lastMessage.message, topic);
                    const bubble = createMessageBubble(nextPersona, response, 
                                                     nextPersona === persona1 ? 'left' : 'right');
                    dialogueContainer.appendChild(bubble);
                    dialogueHistory.push({persona: nextPersona, message: response});
                    
                    // Scroll to bottom
                    dialogueContainer.scrollTop = dialogueContainer.scrollHeight;
                    
                    // Increment phase counter
                    dialoguePhase++;
                    
                    // After 5 exchanges, show next phase button
                    if (dialoguePhase >= 5) {
                        clearInterval(dialogueInterval);
                        nextPhaseBtn.classList.remove('hidden');
                    }
                }, 1500);
            }
        }
        
        function togglePauseDialogue() {
            isDialoguePaused = !isDialoguePaused;
            pauseDialogueBtn.textContent = isDialoguePaused ? 'Resume' : 'Pause';
            
            if (!isDialoguePaused && dialoguePhase < 5) {
                dialogueInterval = setInterval(generateDialogueExchange, 3000);
            } else if (isDialoguePaused) {
                clearInterval(dialogueInterval);
            }
        }
        
        function nextPhase() {
            dialogueSection.classList.add('hidden');
            refinementSection.classList.remove('hidden');
            
            // Generate the refined outputs
            generateRefinedOutputs();
        }
        
        function generateRefinedOutputs() {
            // Simulate generating the refined outputs
            setTimeout(() => {
                contextOutput.textContent = `The dialogue explored the topic of "${topic}" through the lenses of ${personas[persona1].name} and ${personas[persona2].name}. The ${personas[persona1].name} approached it with ${personas[persona1].description.split('.')[0]}, while the ${personas[persona2].name} brought ${personas[personas[persona2].name.toLowerCase()].description.split('.')[0]}.`;
                
                commonGroundOutput.textContent = `Both personas agreed that ${topic} is a multifaceted concept that ${getCommonGround(persona1, persona2)}. They found commonality in their appreciation for ${getCommonAppreciation(persona1, persona2)}.`;
                
                differencesOutput.textContent = `The main differences emerged in ${getDifferenceArea(persona1, persona2)}. The ${personas[persona1].name} emphasized ${getEmphasis(persona1)}, while the ${personas[persona2].name} focused more on ${getEmphasis(persona2)}.`;
                
                poemOutput.textContent = generatePoem(topic, persona1, persona2);
                
                // Simulate image generation
                setTimeout(() => {
                    imageOutput.innerHTML = `<img src="https://source.unsplash.com/random/600x400/?${encodeURIComponent(topic)},abstract,art" alt="AI generated interpretation of the poem" class="w-full h-full object-cover rounded-lg">`;
                }, 1000);
            }, 500);
        }
        
        function restart() {
            refinementSection.classList.add('hidden');
            personaSection.classList.remove('hidden');
            
            // Reset selections
            persona1Select.value = '';
            persona2Select.value = '';
            topicInput.value = '';
            startDialogueBtn.disabled = true;
        }
        
        function createTypingIndicator(persona) {
            const typingDiv = document.createElement('div');
            typingDiv.className = `flex items-center mb-2 ${persona === persona1 ? 'justify-start' : 'justify-end'}`;
            
            const typingContainer = document.createElement('div');
            typingContainer.className = `typing-indicator bg-${personas[persona].color}-100 rounded-full px-3 py-2`;
            
            for (let i = 0; i < 3; i++) {
                const dot = document.createElement('div');
                dot.className = 'typing-dot';
                typingContainer.appendChild(dot);
            }
            
            typingDiv.appendChild(typingContainer);
            return typingDiv;
        }
        
        function createMessageBubble(persona, message, side) {
            const messageDiv = document.createElement('div');
            messageDiv.className = `flex mb-3 ${side === 'left' ? 'justify-start' : 'justify-end'}`;
            
            const bubbleDiv = document.createElement('div');
            bubbleDiv.className = `dialogue-bubble ${side === 'left' ? 'left-bubble' : 'right-bubble'} fade-in`;
            bubbleDiv.innerHTML = marked.parse(message);
            
            messageDiv.appendChild(bubbleDiv);
            return messageDiv;
        }
        
        // Content generation functions (simplified for demo)
        function generateInitialThought(persona, topic) {
            const personaData = personas[persona];
            
            switch(persona) {
                case 'philosopher':
                    return `As I contemplate "${topic}", I'm drawn to the fundamental questions it raises about human existence. What does it mean to truly experience ${topic}? Is ${topic} an objective reality or a subjective construct of our minds?`;
                case 'poet':
                    return `Oh, ${topic}! Like a butterfly's wing against the morning dew, so delicate yet bursting with color. How does one capture the essence of ${topic} in mere words? It dances at the edge of perception, always just beyond reach.`;
                case 'historian':
                    return `Looking back through history, ${topic} has played a pivotal role in shaping civilizations. From ancient times to modern era, the pursuit of ${topic} has driven human progress and conflict alike. What lessons can we learn from our ancestors about ${topic}?`;
                case 'critic':
                    return `${topic} presents itself as a fascinating subject for aesthetic analysis. The interplay of form and meaning in ${topic} creates a rich tapestry of interpretation. How do we evaluate ${topic} as both an experience and an artistic construct?`;
                case 'kid':
                    return `Wow, ${topic} is so cool! It's like when you see a rainbow or get a new toy. Why do grown-ups make ${topic} so complicated? It's just awesome!`;
                case 'engineer':
                    return `Examining ${topic} from a systems perspective reveals interesting patterns. The efficiency of ${topic} can be optimized by applying first principles. What are the measurable parameters that define successful ${topic}?`;
                default:
                    return `Let's discuss ${topic}.`;
            }
        }
        
        function generateResponse(persona, lastMessage, topic) {
            const personaData = personas[persona];
            
            switch(persona) {
                case 'philosopher':
                    return `Your perspective on ${topic} raises important epistemological questions. Building on your thoughts, I would argue that ${topic} exists in the interplay between being and becoming. The ancient Greeks might say...`;
                case 'poet':
                    return `Your words about ${topic} sing to my soul! Let me add this verse: "Like ${topic} in spring's embrace, we dance on edges of time and space." There's music in how you describe ${topic}.`;
                case 'historian':
                    return `Fascinating! This reminds me of how ${topic} influenced the Renaissance period. The parallels between then and now regarding ${topic} are striking, wouldn't you agree?`;
                case 'critic':
                    return `I appreciate your analysis of ${topic}. From an art criticism standpoint, we might also consider how ${topic} challenges traditional aesthetic boundaries. The postmodern interpretation would be...`;
                case 'kid':
                    return `Yeah! And ${topic} is also like when you eat ice cream and it's all melty but still yummy! Why can't ${topic} always be fun like that?`;
                case 'engineer':
                    return `Your observations about ${topic} suggest an opportunity for systematic improvement. If we model ${topic} as a function with these variables, we could optimize for better outcomes.`;
                default:
                    return `I'd like to add my thoughts about ${topic}.`;
            }
        }
        
        function getCommonGround(p1, p2) {
            if ((p1 === 'philosopher' && p2 === 'historian') || (p1 === 'historian' && p2 === 'philosopher')) {
                return "requires understanding through both time and abstract thought";
            } else if ((p1 === 'poet' && p2 === 'critic') || (p1 === 'critic' && p2 === 'poet')) {
                return "demands deep emotional engagement and aesthetic appreciation";
            } else if ((p1 === 'kid' && p2 === 'engineer') || (p1 === 'engineer' && p2 === 'kid')) {
                return "benefits from both simplicity and systematic thinking";
            } else {
                return "has value that transcends any single perspective";
            }
        }
        
        function getCommonAppreciation(p1, p2) {
            if (p1 === 'philosopher' || p2 === 'philosopher') {
                return "the depth of human thought";
            } else if (p1 === 'poet' || p2 === 'poet') {
                return "the beauty of expression";
            } else if (p1 === 'historian' || p2 === 'historian') {
                return "the lessons of history";
            } else if (p1 === 'critic' || p2 === 'critic') {
                return "the nuances of interpretation";
            } else if (p1 === 'kid' || p2 === 'kid') {
                return "the joy of discovery";
            } else {
                return "the power of innovation";
            }
        }
        
        function getDifferenceArea(p1, p2) {
            if (p1 === 'philosopher' || p2 === 'philosopher') {
                return "the balance between abstract reasoning and practical application";
            } else if (p1 === 'poet' || p2 === 'poet') {
                return "the role of emotion versus analysis";
            } else if (p1 === 'historian' || p2 === 'historian') {
                return "the weight given to historical context versus present experience";
            } else if (p1 === 'critic' || p2 === 'critic') {
                return "the standards used for evaluation";
            } else if (p1 === 'kid' || p2 === 'kid') {
                return "the level of complexity considered valuable";
            } else {
                return "the approach to problem-solving";
            }
        }
        
        function getEmphasis(persona) {
            switch(persona) {
                case 'philosopher': return "theoretical frameworks and logical consistency";
                case 'poet': return "emotional resonance and metaphorical richness";
                case 'historian': return "historical precedents and contextual understanding";
                case 'critic': return "aesthetic principles and interpretive depth";
                case 'kid': return "immediate experience and unfiltered wonder";
                case 'engineer': return "practical applications and systematic solutions";
                default: return "their unique perspective";
            }
        }
        
        function generatePoem(topic, p1, p2) {
            const persona1Data = personas[p1];
            const persona2Data = personas[p2];
            
            return `The ${topic} Dialogue\n\n` +
                   `[${persona1Data.name}'s verse]\n` +
                   `${getPoemVerse(p1, topic)}\n\n` +
                   `[${persona2Data.name}'s response]\n` +
                   `${getPoemVerse(p2, topic)}\n\n` +
                   `[Together]\n` +
                   `In the space between our minds,\n` +
                   `Where ${p1} and ${p2} intertwine,\n` +
                   `${topic} takes a shape so new,\n` +
                   `More than what each alone knew.\n\n` +
                   `Through dialogue we come to see\n` +
                   `The greater truth of ${topic} free,\n` +
                   `From single view or narrow thought,\n` +
                   `A richer understanding wrought.`;
        }
        
        function getPoemVerse(persona, topic) {
            switch(persona) {
                case 'philosopher':
                    return `What is ${topic} but a thought,\n` +
                           `A concept that the mind has caught?\n` +
                           `Beyond the veil of what seems real,\n` +
                           `Its essence we attempt to feel.`;
                case 'poet':
                    return `${topic}! Like a bird in flight,\n` +
                           `A burst of color, pure and bright.\n` +
                           `It sings in hues beyond compare,\n` +
                           `A melody that fills the air.`;
                case 'historian':
                    return `Through ages past ${topic} has grown,\n` +
                           `In seeds of time its truth was sown.\n` +
                           `Each era adds its layer deep,\n` +
                           `In history's book its story's kept.`;
                case 'critic':
                    return `Observe how ${topic} plays its part,\n` +
                           `A work of art that moves the heart.\n` +
                           `Its form and function, light and shade,\n` +
                           `A masterpiece that will not fade.`;
                case 'kid':
                    return `${topic} is fun! It's big! It's wow!\n` +
                           `Like puppies playing, here and now!\n` +
                           `Why make it hard? It's simple, see?\n` +
                           `Just be happy, like ${topic} makes me!`;
                case 'engineer':
                    return `The system of ${topic}, clean and neat,\n` +
                           `Efficient patterns, logic sweet.\n` +
                           `Optimized for perfect flow,\n` +
                           `A well-designed conceptual show.`;
                default:
                    return `About ${topic} I have much to say,\n` +
                           `In my own special way.\n` +
                           `Let's share our thoughts and then we'll see\n` +
                           `The ${topic} that emerges free.`;
            }
        }
        
        // Check for existing token in sessionStorage
        if (sessionStorage.getItem('hfToken')) {
            hfTokenInput.value = sessionStorage.getItem('hfToken');
            authBtn.click();
        }
    </script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Dumoura/frontend-of-reductive-dialogue" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>