akhaliq HF Staff commited on
Commit
58dc514
Β·
verified Β·
1 Parent(s): ce95310

Upload index.html with huggingface_hub

Browse files
Files changed (1) hide show
  1. index.html +374 -19
index.html CHANGED
@@ -1,19 +1,374 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <html lang="en">
2
+ <head>
3
+ <meta charset="UTF-8">
4
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
5
+ <title>AI Chat Assistant - Gradio Lite</title>
6
+ <script type="module" crossorigin src="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.js"></script>
7
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.css" />
8
+ <style>
9
+ * {
10
+ margin: 0;
11
+ padding: 0;
12
+ box-sizing: border-box;
13
+ }
14
+
15
+ body {
16
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
17
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
18
+ min-height: 100vh;
19
+ display: flex;
20
+ flex-direction: column;
21
+ align-items: center;
22
+ padding: 20px;
23
+ }
24
+
25
+ .container {
26
+ width: 100%;
27
+ max-width: 1200px;
28
+ background: white;
29
+ border-radius: 20px;
30
+ box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
31
+ overflow: hidden;
32
+ animation: slideIn 0.5s ease-out;
33
+ }
34
+
35
+ @keyframes slideIn {
36
+ from {
37
+ opacity: 0;
38
+ transform: translateY(30px);
39
+ }
40
+ to {
41
+ opacity: 1;
42
+ transform: translateY(0);
43
+ }
44
+ }
45
+
46
+ .header {
47
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
48
+ color: white;
49
+ padding: 30px;
50
+ text-align: center;
51
+ }
52
+
53
+ .header h1 {
54
+ font-size: 2.5rem;
55
+ margin-bottom: 10px;
56
+ font-weight: 700;
57
+ text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
58
+ }
59
+
60
+ .header p {
61
+ font-size: 1.1rem;
62
+ opacity: 0.95;
63
+ margin-bottom: 20px;
64
+ }
65
+
66
+ .features {
67
+ display: flex;
68
+ justify-content: center;
69
+ gap: 30px;
70
+ margin-top: 20px;
71
+ flex-wrap: wrap;
72
+ }
73
+
74
+ .feature {
75
+ display: flex;
76
+ align-items: center;
77
+ gap: 8px;
78
+ background: rgba(255, 255, 255, 0.2);
79
+ padding: 8px 16px;
80
+ border-radius: 20px;
81
+ backdrop-filter: blur(10px);
82
+ }
83
+
84
+ .feature-icon {
85
+ font-size: 1.2rem;
86
+ }
87
+
88
+ .app-container {
89
+ padding: 40px;
90
+ background: #f8f9fa;
91
+ min-height: 600px;
92
+ }
93
+
94
+ .loading-message {
95
+ text-align: center;
96
+ padding: 40px;
97
+ color: #666;
98
+ }
99
+
100
+ .loading-spinner {
101
+ display: inline-block;
102
+ width: 50px;
103
+ height: 50px;
104
+ border: 3px solid rgba(0, 0, 0, 0.1);
105
+ border-radius: 50%;
106
+ border-top-color: #667eea;
107
+ animation: spin 1s ease-in-out infinite;
108
+ margin-bottom: 20px;
109
+ }
110
+
111
+ @keyframes spin {
112
+ to { transform: rotate(360deg); }
113
+ }
114
+
115
+ .info-cards {
116
+ display: grid;
117
+ grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
118
+ gap: 20px;
119
+ padding: 20px;
120
+ margin-bottom: 30px;
121
+ }
122
+
123
+ .info-card {
124
+ background: white;
125
+ border-radius: 12px;
126
+ padding: 20px;
127
+ box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
128
+ transition: transform 0.3s ease, box-shadow 0.3s ease;
129
+ }
130
+
131
+ .info-card:hover {
132
+ transform: translateY(-5px);
133
+ box-shadow: 0 5px 20px rgba(0, 0, 0, 0.12);
134
+ }
135
+
136
+ .info-card h3 {
137
+ color: #667eea;
138
+ margin-bottom: 10px;
139
+ font-size: 1.2rem;
140
+ }
141
+
142
+ .info-card p {
143
+ color: #666;
144
+ line-height: 1.6;
145
+ }
146
+
147
+ @media (max-width: 768px) {
148
+ .header h1 {
149
+ font-size: 1.8rem;
150
+ }
151
+
152
+ .header p {
153
+ font-size: 1rem;
154
+ }
155
+
156
+ .features {
157
+ gap: 10px;
158
+ }
159
+
160
+ .app-container {
161
+ padding: 20px;
162
+ }
163
+ }
164
+
165
+ .tech-badge {
166
+ display: inline-block;
167
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
168
+ color: white;
169
+ padding: 4px 12px;
170
+ border-radius: 12px;
171
+ font-size: 0.85rem;
172
+ margin: 5px;
173
+ }
174
+
175
+ gradio-lite {
176
+ width: 100%;
177
+ min-height: 500px;
178
+ }
179
+ </style>
180
+ </head>
181
+ <body>
182
+ <div class="container">
183
+ <div class="header">
184
+ <h1>πŸ€– AI Chat Assistant</h1>
185
+ <p>Powered by Gemma 270M Model & Hugging Face Transformers</p>
186
+ <div class="features">
187
+ <div class="feature">
188
+ <span class="feature-icon">⚑</span>
189
+ <span>Fast Inference</span>
190
+ </div>
191
+ <div class="feature">
192
+ <span class="feature-icon">πŸ”’</span>
193
+ <span>100% Browser-Based</span>
194
+ </div>
195
+ <div class="feature">
196
+ <span class="feature-icon">🌐</span>
197
+ <span>No Server Required</span>
198
+ </div>
199
+ </div>
200
+ </div>
201
+
202
+ <div class="info-cards">
203
+ <div class="info-card">
204
+ <h3>πŸ’‘ How It Works</h3>
205
+ <p>This application runs entirely in your browser using WebAssembly and Pyodide. The AI model is loaded directly in your browser for complete privacy and offline capability.</p>
206
+ </div>
207
+ <div class="info-card">
208
+ <h3>πŸš€ Technologies Used</h3>
209
+ <p>
210
+ <span class="tech-badge">Gradio Lite</span>
211
+ <span class="tech-badge">Hugging Face</span>
212
+ <span class="tech-badge">ONNX Runtime</span>
213
+ <span class="tech-badge">WebAssembly</span>
214
+ </p>
215
+ </div>
216
+ <div class="info-card">
217
+ <h3>πŸ“ Getting Started</h3>
218
+ <p>Simply type your message in the chat interface below. The AI will process your request locally and generate a response using the Gemma model.</p>
219
+ </div>
220
+ </div>
221
+
222
+ <div class="app-container">
223
+ <div class="loading-message">
224
+ <div class="loading-spinner"></div>
225
+ <h3>Loading AI Model...</h3>
226
+ <p>This may take 10-30 seconds on first load as we download and initialize the model.</p>
227
+ </div>
228
+
229
+ <gradio-lite theme="light">
230
+ <gradio-requirements>
231
+ transformers_js_py
232
+ </gradio-requirements>
233
+
234
+ <gradio-file name="app.py" entrypoint>
235
+ import gradio as gr
236
+ from transformers_js import import_transformers_js
237
+ import asyncio
238
+
239
+ # Import transformers.js
240
+ transformers = await import_transformers_js()
241
+ pipeline = transformers.pipeline
242
+ TextStreamer = transformers.TextStreamer
243
+
244
+ # Initialize the model pipeline
245
+ print("Loading model... This may take a moment.")
246
+ generator = await pipeline(
247
+ "text-generation",
248
+ "onnx-community/gemma-3-270m-it-ONNX",
249
+ {
250
+ "dtype": "fp32",
251
+ }
252
+ )
253
+
254
+ # Store conversation history
255
+ conversation_history = []
256
+
257
+ async def chat_with_ai(message, history):
258
+ """Process user message and generate AI response"""
259
+ if not message:
260
+ return history
261
+
262
+ # Format the conversation for the model
263
+ messages = [
264
+ {"role": "system", "content": "You are a helpful AI assistant. Provide clear, concise, and informative responses."},
265
+ ]
266
+
267
+ # Add conversation history
268
+ for user_msg, assistant_msg in history:
269
+ messages.append({"role": "user", "content": user_msg})
270
+ messages.append({"role": "assistant", "content": assistant_msg})
271
+
272
+ # Add current message
273
+ messages.append({"role": "user", "content": message})
274
+
275
+ try:
276
+ # Generate response
277
+ output = await generator(messages, {
278
+ "max_new_tokens": 256,
279
+ "temperature": 0.7,
280
+ "do_sample": True,
281
+ "top_p": 0.9,
282
+ })
283
+
284
+ # Extract the assistant's response
285
+ response = output[0]["generated_text"][-1]["content"]
286
+
287
+ # Update history
288
+ history.append([message, response])
289
+ return history
290
+
291
+ except Exception as e:
292
+ error_msg = f"Error generating response: {str(e)}"
293
+ history.append([message, error_msg])
294
+ return history
295
+
296
+ def clear_chat():
297
+ """Clear the conversation history"""
298
+ return []
299
+
300
+ # Create the Gradio interface
301
+ with gr.Blocks(title="AI Chat Assistant") as demo:
302
+ gr.Markdown(
303
+ """
304
+ # πŸ€– AI Chat Assistant
305
+ Chat with an AI powered by the Gemma model running entirely in your browser!
306
+ """
307
+ )
308
+
309
+ chatbot = gr.Chatbot(
310
+ height=400,
311
+ placeholder="Start chatting with the AI assistant...",
312
+ bubble_full_width=False,
313
+ )
314
+
315
+ with gr.Row():
316
+ msg = gr.Textbox(
317
+ placeholder="Type your message here and press Enter...",
318
+ label="Your Message",
319
+ lines=2,
320
+ scale=4
321
+ )
322
+ submit_btn = gr.Button("Send", variant="primary", scale=1)
323
+
324
+ with gr.Row():
325
+ clear_btn = gr.Button("πŸ—‘οΈ Clear Chat", variant="secondary")
326
+
327
+ gr.Examples(
328
+ examples=[
329
+ "What is machine learning?",
330
+ "Write a short poem about technology",
331
+ "Explain quantum computing in simple terms",
332
+ "What are the benefits of renewable energy?",
333
+ "How does the internet work?",
334
+ ],
335
+ inputs=msg,
336
+ label="Example Questions"
337
+ )
338
+
339
+ # Set up event handlers
340
+ msg.submit(chat_with_ai, [msg, chatbot], chatbot)
341
+ msg.submit(lambda: "", None, msg)
342
+
343
+ submit_btn.click(chat_with_ai, [msg, chatbot], chatbot)
344
+ submit_btn.click(lambda: "", None, msg)
345
+
346
+ clear_btn.click(clear_chat, None, chatbot)
347
+
348
+ gr.Markdown(
349
+ """
350
+ ---
351
+ **Note:** This model runs entirely in your browser. No data is sent to any server.
352
+ Initial loading may take some time as the model is downloaded and initialized.
353
+ """
354
+ )
355
+
356
+ demo.launch()
357
+ </gradio-file>
358
+ </gradio-lite>
359
+ </div>
360
+ </div>
361
+
362
+ <script>
363
+ // Hide loading message when Gradio app loads
364
+ window.addEventListener('load', () => {
365
+ setTimeout(() => {
366
+ const loadingMsg = document.querySelector('.loading-message');
367
+ if (loadingMsg) {
368
+ loadingMsg.style.display = 'none';
369
+ }
370
+ }, 5000);
371
+ });
372
+ </script>
373
+ </body>
374
+ </html>