Spaces:
Running
Running
Upload index.html with huggingface_hub
Browse files- index.html +116 -0
index.html
ADDED
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Piper ONNX Converter</title>
|
7 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.1/socket.io.js"></script>
|
8 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
9 |
+
</head>
|
10 |
+
<body class="bg-gray-100 min-h-screen flex items-center justify-center">
|
11 |
+
<div class="container mx-auto px-4">
|
12 |
+
<h1 class="text-3xl font-bold mb-8 text-center">Piper ONNX Converter</h1>
|
13 |
+
<form id="converterForm" class="bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4">
|
14 |
+
<div class="mb-4">
|
15 |
+
<label class="block text-gray-700 text-sm font-bold mb-2" for="repo_id">
|
16 |
+
Hugging Face Repository ID:
|
17 |
+
</label>
|
18 |
+
<input class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" id="repo_id" name="repo_id" type="text" required>
|
19 |
+
</div>
|
20 |
+
<div class="mb-4">
|
21 |
+
<label class="block text-gray-700 text-sm font-bold mb-2" for="token">
|
22 |
+
Hugging Face Token:
|
23 |
+
</label>
|
24 |
+
<input class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" id="token" name="token" type="password" required>
|
25 |
+
</div>
|
26 |
+
<div class="mb-6">
|
27 |
+
<label class="block text-gray-700 text-sm font-bold mb-2" for="model_name">
|
28 |
+
Model Name:
|
29 |
+
</label>
|
30 |
+
<input class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" id="model_name" name="model_name" type="text" required>
|
31 |
+
</div>
|
32 |
+
<div class="flex items-center justify-between">
|
33 |
+
<button class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline" type="submit">
|
34 |
+
Convert and Download
|
35 |
+
</button>
|
36 |
+
</div>
|
37 |
+
</form>
|
38 |
+
|
39 |
+
<div id="progress" class="bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4" style="display: none;">
|
40 |
+
<h2 class="text-2xl font-bold mb-4">Processing...</h2>
|
41 |
+
<div id="log" class="bg-gray-100 p-4 rounded-lg h-64 overflow-y-auto mb-4"></div>
|
42 |
+
<a id="downloadLink" class="bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline" style="display: none;">Download Converted Model</a>
|
43 |
+
</div>
|
44 |
+
</div>
|
45 |
+
|
46 |
+
<script>
|
47 |
+
const form = document.getElementById('converterForm');
|
48 |
+
const progress = document.getElementById('progress');
|
49 |
+
const log = document.getElementById('log');
|
50 |
+
const downloadLink = document.getElementById('downloadLink');
|
51 |
+
|
52 |
+
const socket = io();
|
53 |
+
|
54 |
+
socket.on('task_update', function(data) {
|
55 |
+
const logEntry = document.createElement('p');
|
56 |
+
logEntry.textContent = data.message;
|
57 |
+
log.appendChild(logEntry);
|
58 |
+
log.scrollTop = log.scrollHeight;
|
59 |
+
|
60 |
+
// Check if the message contains the download URL
|
61 |
+
if (data.message.includes("Processing completed. Download URL:")) {
|
62 |
+
const url = data.message.split("Download URL: ")[1];
|
63 |
+
downloadLink.href = url;
|
64 |
+
downloadLink.style.display = 'inline-block';
|
65 |
+
}
|
66 |
+
});
|
67 |
+
|
68 |
+
form.addEventListener('submit', async (e) => {
|
69 |
+
e.preventDefault();
|
70 |
+
const formData = new FormData(form);
|
71 |
+
|
72 |
+
try {
|
73 |
+
const response = await fetch('/', {
|
74 |
+
method: 'POST',
|
75 |
+
body: formData
|
76 |
+
});
|
77 |
+
const data = await response.json();
|
78 |
+
|
79 |
+
if (data.task_id) {
|
80 |
+
form.style.display = 'none';
|
81 |
+
progress.style.display = 'block';
|
82 |
+
pollStatus(data.task_id);
|
83 |
+
}
|
84 |
+
} catch (error) {
|
85 |
+
console.error('Error:', error);
|
86 |
+
}
|
87 |
+
});
|
88 |
+
|
89 |
+
async function pollStatus(taskId) {
|
90 |
+
while (true) {
|
91 |
+
try {
|
92 |
+
const response = await fetch(`/status/${taskId}`);
|
93 |
+
const data = await response.json();
|
94 |
+
|
95 |
+
if (data.status === 'completed') {
|
96 |
+
// We don't need to set the download link here anymore
|
97 |
+
// as it's now handled in the socket.on('task_update') function
|
98 |
+
break;
|
99 |
+
} else if (data.status === 'error') {
|
100 |
+
const errorMsg = document.createElement('p');
|
101 |
+
errorMsg.textContent = 'An error occurred during processing.';
|
102 |
+
errorMsg.classList.add('text-red-500', 'font-bold');
|
103 |
+
log.appendChild(errorMsg);
|
104 |
+
break;
|
105 |
+
}
|
106 |
+
|
107 |
+
await new Promise(resolve => setTimeout(resolve, 5000)); // Poll every 5 seconds
|
108 |
+
} catch (error) {
|
109 |
+
console.error('Error polling status:', error);
|
110 |
+
break;
|
111 |
+
}
|
112 |
+
}
|
113 |
+
}
|
114 |
+
</script>
|
115 |
+
</body>
|
116 |
+
</html>
|