File size: 4,599 Bytes
ab9f226
dd1b723
 
9161cfa
 
 
 
 
 
dd1b723
 
9161cfa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dd1b723
9161cfa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dd1b723
9161cfa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dd1b723
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Gemma AI Chatbot</title>
    <link rel="stylesheet" href="style.css">
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
</head>
<body>
    <div class="app-container">
        <!-- Header -->
        <header class="header">
            <div class="header-content">
                <div class="logo">
                    <i class="fas fa-robot"></i>
                    <h1>Gemma AI Chatbot</h1>
                </div>
                <div class="device-toggle">
                    <span class="device-label">Execution:</span>
                    <button id="deviceToggle" class="device-btn">
                        <span class="device-option active" data-device="cpu">CPU</span>
                        <span class="device-option" data-device="webgpu">GPU</span>
                    </button>
                    <div class="status-indicator">
                        <i class="fas fa-circle"></i>
                        <span id="statusText">Loading...</span>
                    </div>
                </div>
            </div>
            <div class="credit">
                Built with <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" rel="noopener noreferrer">anycoder</a>
            </div>
        </header>

        <!-- Main Chat Area -->
        <main class="main-content">
            <div class="chat-container">
                <div class="messages-container" id="messagesContainer">
                    <div class="welcome-message">
                        <div class="welcome-icon">
                            <i class="fas fa-comments"></i>
                        </div>
                        <h2>Welcome to Gemma AI Chatbot</h2>
                        <p>Start a conversation with the AI assistant. I'm here to help with any questions you have!</p>
                    </div>
                </div>
                
                <!-- Input Area -->
                <div class="input-container">
                    <div class="input-wrapper">
                        <textarea 
                            id="messageInput" 
                            placeholder="Type your message here..." 
                            rows="1"
                            disabled
                        ></textarea>
                        <button id="sendButton" class="send-button" disabled>
                            <i class="fas fa-paper-plane"></i>
                        </button>
                    </div>
                    <div class="input-footer">
                        <span class="model-info">
                            <i class="fas fa-microchip"></i>
                            Model: gemma-3-270m-it-ONNX
                        </span>
                        <span class="char-count">
                            <span id="charCount">0</span>/1000
                        </span>
                    </div>
                </div>
            </div>
        </main>

        <!-- Loading Overlay -->
        <div class="loading-overlay" id="loadingOverlay">
            <div class="loading-content">
                <div class="loading-spinner">
                    <div class="spinner"></div>
                </div>
                <h3>Initializing AI Model</h3>
                <p>Please wait while we load the Gemma AI model...</p>
                <div class="progress-bar">
                    <div class="progress-fill" id="progressFill"></div>
                </div>
            </div>
        </div>

        <!-- Error Modal -->
        <div class="error-modal" id="errorModal">
            <div class="error-content">
                <div class="error-icon">
                    <i class="fas fa-exclamation-triangle"></i>
                </div>
                <h3>Error</h3>
                <p id="errorMessage">An error occurred while initializing the AI model.</p>
                <button class="retry-button" id="retryButton">Retry</button>
            </div>
        </div>
    </div>

    <!-- Transformers.js Import -->
    <script type="module">
        import { pipeline, TextStreamer } from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.7.3';
        window.transformers = { pipeline, TextStreamer };
    </script>
    <script src="index.js"></script>
</body>
</html>