-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
90 lines (80 loc) · 3.64 KB
/
index.html
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.16/dist/tailwind.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.0/css/all.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" />
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<title>Token Counter</title>
</head>
<body class="bg-gray-100">
<div class="container mx-auto px-4 py-5">
<h1 class="text-4xl font-bold mb-8 text-blue-600">Token Counter</h1>
<div class="bg-white p-6 rounded-lg shadow-md">
<form method="post" class="space-y-4">
<div>
<label for="text" class="block text-gray-700">Text:</label>
<textarea class="form-control w-full p-2 border border-gray-300 rounded" id="text" name="text" rows="5">{{ text }}</textarea>
</div>
<div>
<label for="model_name" class="block text-gray-700">Model:</label>
<select class="form-control w-full p-2 border border-gray-300 rounded" id="model_name" name="model_name">
<optgroup label="Top Models">
<!-- Top models will be populated using JavaScript -->
</optgroup>
<optgroup label="Recent Uploads">
<!-- Recent models will be populated using JavaScript -->
</optgroup>
</select>
</div>
<button type="submit" class="btn btn-primary px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">Count Tokens</button>
</form>
</div>
{% if token_count %}
<div class="mt-6 bg-green-100 border-l-4 border-green-500 text-green-700 p-4 rounded-lg">
<p class="text-lg font-semibold">Token count: {{ token_count }}</p>
</div>
{% endif %}
{% if error %}
<div class="mt-6 bg-red-100 border-l-4 border-red-500 text-red-700 p-4 rounded-lg">
<p class="font-semibold"><i class="fas fa-exclamation-circle mr-2"></i>Error: {{ error }}</p>
</div>
{% endif %}
</div>
<script>
async function fetchModels() {
const response = await fetch('https://huggingface.co/api/models');
const data = await response.json();
// Extract relevant model information
const models = data.map(model => ({
label: model.modelId,
value: model.modelId,
downloads: model.downloads,
createdAt: new Date(model.createdAt)
}));
// Sort models by downloads and createdAt
const topDownloads = models.sort((a, b) => b.downloads - a.downloads).slice(0, 3);
const recentUploads = models.sort((a, b) => b.createdAt - a.createdAt).slice(0, 3);
return { topDownloads, recentUploads, allModels: models };
}
fetchModels().then(({ topDownloads, recentUploads, allModels }) => {
populateModelOptions(topDownloads, 'Top Models');
populateModelOptions(recentUploads, 'Recent Uploads');
$("#model_name").autocomplete({
source: function (request, response) {
const results = $.ui.autocomplete.filter(allModels, request.term);
response(results.slice(0, 5));
},
minLength: 0,
delay: 200,
autoFocus: true
}).on('focus', function () {
$(this).autocomplete('search', '');
});
});
</script>
</body>
</html>