jscmp4 commited on
Commit
9ddcbbe
·
verified ·
1 Parent(s): 6960dba
Files changed (1) hide show
  1. index.html +70 -19
index.html CHANGED
@@ -1,19 +1,70 @@
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
+ <!DOCTYPE html>
2
+ <html lang="zh-CN">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>WebGPU 冒烟测试</title>
6
+ <style>
7
+ body { font-family: sans-serif; padding: 20px; line-height: 1.6; }
8
+ .box { background: #f0f0f0; padding: 15px; border-radius: 8px; margin-bottom: 10px; }
9
+ .success { color: green; font-weight: bold; }
10
+ .error { color: red; font-weight: bold; }
11
+ button { font-size: 16px; padding: 10px 20px; cursor: pointer; }
12
+ </style>
13
+ </head>
14
+ <body>
15
+
16
+ <h1>🔥 冒烟测试 (Smoke Test)</h1>
17
+ <p>如果下面两步都显示绿色,说明你的“地基”已经搭好了。</p>
18
+
19
+ <div class="box">
20
+ <h3>1. 环境检查</h3>
21
+ <div id="env-status">正在检查浏览器环境...</div>
22
+ </div>
23
+
24
+ <div class="box">
25
+ <h3>2. 模型加载测试 (Whisper-Tiny)</h3>
26
+ <p>点击按钮,测试是否能从 Hugging Face 拉取模型到本地。</p>
27
+ <button id="load-btn">开始加载模型</button>
28
+ <div id="model-status" style="margin-top:10px; color:#666;">等待指令...</div>
29
+ </div>
30
+
31
+ <script type="module">
32
+ // 引入库
33
+ import { pipeline, env } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers@2.17.2';
34
+
35
+ const envStatus = document.getElementById('env-status');
36
+ const modelStatus = document.getElementById('model-status');
37
+ const btn = document.getElementById('load-btn');
38
+
39
+ // 1. 环境检查逻辑
40
+ // 简单检查 navigator.gpu 是否存在 (这是 WebGPU 的标志)
41
+ if ("gpu" in navigator) {
42
+ envStatus.innerHTML = "✅ 检测到 WebGPU 支持!你的浏览器很棒。";
43
+ envStatus.className = "success";
44
+ } else {
45
+ envStatus.innerHTML = "⚠️ 未检测到 WebGPU,将回退到 WASM (CPU) 模式,速度会慢一些,但也能用。";
46
+ envStatus.className = "error"; // 其实不算致命错误,只是性能会差
47
+ }
48
+
49
+ // 2. 模型加载逻辑
50
+ btn.addEventListener('click', async () => {
51
+ btn.disabled = true;
52
+ modelStatus.innerText = "⏳ 正在连接 HF Hub 下载模型 (约 40MB)...";
53
+
54
+ try {
55
+ // 尝试加载最小的语音识别模型
56
+ let pipe = await pipeline('automatic-speech-recognition', 'Xenova/whisper-tiny');
57
+
58
+ modelStatus.innerHTML = "✅ 模型加载成功!引擎已就绪。";
59
+ modelStatus.className = "success";
60
+ console.log(pipe); // 在控制台打印模型对象
61
+ } catch (err) {
62
+ modelStatus.innerHTML = "❌ 加载失败: " + err.message;
63
+ modelStatus.className = "error";
64
+ console.error(err);
65
+ btn.disabled = false;
66
+ }
67
+ });
68
+ </script>
69
+ </body>
70
+ </html>