Spaces:
Running

File size: 6,781 Bytes
5e30092
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
df3679d
0ba43ec
 
 
 
 
df3679d
0ba43ec
 
df3679d
 
4f6c27f
df3679d
 
 
0ba43ec
4f6c27f
 
df3679d
 
4f6c27f
df3679d
5e30092
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
df3679d
a81691f
a56fa61
 
a81691f
 
 
a56fa61
 
a81691f
 
 
 
 
a56fa61
a81691f
 
 
a56fa61
 
a81691f
a56fa61
 
a81691f
 
 
 
 
 
 
 
 
 
a56fa61
 
 
 
 
 
a81691f
df3679d
5e30092
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Ethereal messaging interface with voice input">
    <meta name="theme-color" content="#7e22ce">
    <title>Ethereal Messenger</title>
    <link rel="icon" type="image/x-icon" href="/static/favicon.ico">
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
    <script src="https://unpkg.com/feather-icons"></script>
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600&display=swap');
        body {
            font-family: 'Inter', sans-serif;
            background: linear-gradient(135deg, #7e22ce 0%, #3b82f6 100%);
            color: rgba(236, 253, 245, 0.95);
            min-height: 100vh;
        }
        .message-display {
            background: rgba(255, 255, 255, 0.08);
            backdrop-filter: blur(12px);
            border: 1px solid rgba(255, 255, 255, 0.1);
        }
        .text-input {
            background: rgba(255, 255, 255, 0.1);
            color: rgba(236, 253, 245, 0.95);
        }
        .text-input::placeholder {
            color: rgba(236, 253, 245, 0.6);
        }
        .send-btn {
            background: rgba(167, 139, 250, 0.3);
            transition: all 0.2s ease;
        }
        .send-btn:hover {
            background: rgba(167, 139, 250, 0.5);
        }
        .voice-btn {
            background: rgba(74, 222, 128, 0.3);
            transition: all 0.2s ease;
        }
        .voice-btn:hover {
            background: rgba(74, 222, 128, 0.5);
        }
    </style>
</head>
<body class="flex flex-col">
    <header class="p-4">
        <h1 class="text-2xl font-semibold text-center">Ethereal Messenger</h1>
    </header>

    <main class="flex-1 p-4 max-w-3xl w-full mx-auto">
        <div id="messageDisplay" class="message-display rounded-xl p-4 h-96 overflow-y-auto mb-4 shadow-lg">
            <!-- Messages will appear here dynamically -->
            <div class="text-center text-opacity-60 pt-32">
                <i data-feather="message-circle" class="w-12 h-12 mx-auto opacity-40"></i>
                <p class="mt-2">Your messages will appear here</p>
            </div>
        </div>

        <div class="flex space-x-2">
            <input 
                type="text" 
                id="messageInput" 
                class="text-input flex-1 rounded-lg px-4 py-3 focus:outline-none focus:ring-2 focus:ring-purple-300 focus:ring-opacity-50" 
                placeholder="Type your message..."
                autocomplete="off"
            >
            <button id="sendButton" class="send-btn rounded-lg px-4 flex items-center justify-center">
                <i data-feather="send" class="w-5 h-5"></i>
            </button>
            <button id="voiceButton" class="voice-btn rounded-lg px-4 flex items-center justify-center">
                <i data-feather="mic" class="w-5 h-5"></i>
            </button>
        </div>
    </main>

    <footer class="p-4 text-center text-sm text-opacity-60">
        <p>© 2023 Ethereal Messenger. All rights reserved.</p>
    </footer>




  ;


  <script type="module">
// import { pipeline } from '@huggingface/transformers'
    import { pipeline } from "https://cdn.jsdelivr.net/npm/@xenova/transformers";

  // Initialize Whisper transcription pipeline
  window.transcriber = await pipeline(
    "automatic-speech-recognition",
    "Xenova/whisper-tiny.en"
  );
// Transcribe audio from URL with timestamps
// const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/jfk.wav';
// const result = await transcriber(url, { return_timestamps: true });

  // Show output on screen
  // addMessage("Transcription: " + result.text, false);
</script>
    <script>
        feather.replace();
        
        // Basic message handling for demonstration
        const messageDisplay = document.getElementById('messageDisplay');
        const messageInput = document.getElementById('messageInput');
        const sendButton = document.getElementById('sendButton');
        const voiceButton = document.getElementById('voiceButton');

        function addMessage(text, isUser = true) {
            const messageElement = document.createElement('div');
            messageElement.className = `mb-3 p-3 rounded-lg max-w-xs ${isUser ? 'ml-auto bg-purple-500 bg-opacity-30' : 'mr-auto bg-blue-500 bg-opacity-30'}`;
            messageElement.textContent = text;
            messageDisplay.appendChild(messageElement);
            messageDisplay.scrollTop = messageDisplay.scrollHeight;
        }

        sendButton.addEventListener('click', () => {
            const message = messageInput.value.trim();
            if (message) {
                addMessage(message);
                messageInput.value = '';
                
                // Simulate response after 1 second
                setTimeout(() => {
                    addMessage("This is a simulated response.", false);
                }, 1000);
            }
        });

        messageInput.addEventListener('keypress', (e) => {
            if (e.key === 'Enter') {
                sendButton.click();
            }
        });


      voiceButton.addEventListener('click', async () => {
        console.log("🎤 Voice button clicked");
        
        addMessage("Listening... 🎤 Say something now");
      
        const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
        console.log("✅ Microphone access granted");
        
        const mediaRecorder = new MediaRecorder(stream);
        let chunks = [];
      
        mediaRecorder.addEventListener("dataavailable", event => {
          chunks.push(event.data);
          console.log("📥 Audio chunk received:", event.data);
        });
      
        mediaRecorder.addEventListener("stop", async () => {
        console.log("🛑 Recording stopped");
          
          const blob = new Blob(chunks, { type: 'audio/webm' });
          console.log("🎧 Audio Blob created:", blob);
          
          const result = await window.transcriber(blob);
          console.log("Whisper output:", result.text);
      
          messageInput.value = result.text;
          messageInput.focus();
      
          addMessage("Voice input loaded into text box ✔️", false);
        });
      
        mediaRecorder.start();
        console.log("▶️ Recording started");
        
        setTimeout(() => {
    console.log("⏱️ Timer ended — stopping recording...");
    mediaRecorder.stop();
  }, 3000);
      });
      
    </script>
</body>
</html>