selvaonline commited on
Commit
3d1373a
·
verified ·
1 Parent(s): aa20c05

Upload demo.html with huggingface_hub

Browse files
Files changed (1) hide show
  1. demo.html +191 -0
demo.html ADDED
@@ -0,0 +1,191 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>Shopping Assistant Demo</title>
7
+ <style>
8
+ body {
9
+ font-family: Arial, sans-serif;
10
+ max-width: 800px;
11
+ margin: 0 auto;
12
+ padding: 20px;
13
+ line-height: 1.6;
14
+ }
15
+ h1 {
16
+ color: #2c3e50;
17
+ text-align: center;
18
+ }
19
+ .container {
20
+ border: 1px solid #ddd;
21
+ border-radius: 5px;
22
+ padding: 20px;
23
+ margin-top: 20px;
24
+ }
25
+ .form-group {
26
+ margin-bottom: 15px;
27
+ }
28
+ label {
29
+ display: block;
30
+ margin-bottom: 5px;
31
+ font-weight: bold;
32
+ }
33
+ input[type="text"] {
34
+ width: 100%;
35
+ padding: 8px;
36
+ border: 1px solid #ddd;
37
+ border-radius: 4px;
38
+ box-sizing: border-box;
39
+ }
40
+ button {
41
+ background-color: #3498db;
42
+ color: white;
43
+ border: none;
44
+ padding: 10px 15px;
45
+ border-radius: 4px;
46
+ cursor: pointer;
47
+ }
48
+ button:hover {
49
+ background-color: #2980b9;
50
+ }
51
+ #result {
52
+ margin-top: 20px;
53
+ padding: 15px;
54
+ border: 1px solid #ddd;
55
+ border-radius: 4px;
56
+ background-color: #f9f9f9;
57
+ white-space: pre-wrap;
58
+ display: none;
59
+ }
60
+ .loading {
61
+ text-align: center;
62
+ margin-top: 20px;
63
+ display: none;
64
+ }
65
+ .category {
66
+ display: inline-block;
67
+ margin: 5px;
68
+ padding: 5px 10px;
69
+ border-radius: 15px;
70
+ color: white;
71
+ font-size: 14px;
72
+ }
73
+ .electronics { background-color: #3498db; }
74
+ .clothing { background-color: #9b59b6; }
75
+ .home { background-color: #2ecc71; }
76
+ .kitchen { background-color: #e74c3c; }
77
+ .toys { background-color: #f39c12; }
78
+ .other { background-color: #95a5a6; }
79
+ </style>
80
+ </head>
81
+ <body>
82
+ <h1>Shopping Assistant Demo</h1>
83
+
84
+ <div class="container">
85
+ <p>
86
+ This demo shows how to use the Shopping Assistant model to classify shopping queries into categories.
87
+ Enter a shopping query below to see which categories it belongs to.
88
+ </p>
89
+
90
+ <div class="form-group">
91
+ <label for="query">Shopping Query:</label>
92
+ <input type="text" id="query" placeholder="e.g., I'm looking for headphones" value="I'm looking for headphones">
93
+ </div>
94
+
95
+ <button id="submit">Classify Query</button>
96
+
97
+ <div class="loading" id="loading">
98
+ <p>Classifying your query...</p>
99
+ </div>
100
+
101
+ <div id="result"></div>
102
+ </div>
103
+
104
+ <script>
105
+ document.getElementById('submit').addEventListener('click', async () => {
106
+ const query = document.getElementById('query').value.trim();
107
+ if (!query) {
108
+ alert('Please enter a shopping query');
109
+ return;
110
+ }
111
+
112
+ const loading = document.getElementById('loading');
113
+ const result = document.getElementById('result');
114
+
115
+ loading.style.display = 'block';
116
+ result.style.display = 'none';
117
+
118
+ try {
119
+ // Replace with your actual model ID
120
+ const modelId = 'selvaonline/shopping-assistant';
121
+ const response = await fetch(
122
+ `https://api-inference.huggingface.co/models/${modelId}`,
123
+ {
124
+ method: 'POST',
125
+ headers: {
126
+ 'Content-Type': 'application/json',
127
+ // Uncomment and add your API token if needed
128
+ // 'Authorization': 'Bearer YOUR_API_TOKEN'
129
+ },
130
+ body: JSON.stringify({
131
+ inputs: query,
132
+ options: {
133
+ wait_for_model: true
134
+ }
135
+ })
136
+ }
137
+ );
138
+
139
+ if (!response.ok) {
140
+ throw new Error(`HTTP error! status: ${response.status}`);
141
+ }
142
+
143
+ const data = await response.json();
144
+
145
+ // Process the results
146
+ const categories = ["electronics", "clothing", "home", "kitchen", "toys", "other"];
147
+ const probabilities = data[0].map(logit => 1 / (1 + Math.exp(-logit)));
148
+
149
+ // Get categories with probability > 0.5
150
+ const topCategories = [];
151
+ for (let i = 0; i < probabilities.length; i++) {
152
+ if (probabilities[i] > 0.5) {
153
+ topCategories.push({
154
+ category: categories[i],
155
+ score: probabilities[i]
156
+ });
157
+ }
158
+ }
159
+
160
+ // Sort by score
161
+ topCategories.sort((a, b) => b.score - a.score);
162
+
163
+ // Display the results
164
+ let resultHtml = `<h3>Results for: "${query}"</h3>`;
165
+
166
+ if (topCategories.length > 0) {
167
+ resultHtml += '<p>Top categories:</p>';
168
+ resultHtml += '<div>';
169
+ for (const item of topCategories) {
170
+ resultHtml += `<span class="category ${item.category}">${item.category}: ${item.score.toFixed(4)}</span>`;
171
+ }
172
+ resultHtml += '</div>';
173
+
174
+ resultHtml += `<p>Based on your query, I would recommend looking for deals in the <strong>${topCategories[0].category}</strong> category.</p>`;
175
+ } else {
176
+ resultHtml += '<p>No categories found for your query. Please try a different query.</p>';
177
+ }
178
+
179
+ result.innerHTML = resultHtml;
180
+ result.style.display = 'block';
181
+ } catch (error) {
182
+ console.error('Error:', error);
183
+ result.innerHTML = `<p>Error: ${error.message}</p><p>Make sure the model is available and you have the correct permissions.</p>`;
184
+ result.style.display = 'block';
185
+ } finally {
186
+ loading.style.display = 'none';
187
+ }
188
+ });
189
+ </script>
190
+ </body>
191
+ </html>