electric-otter commited on
Commit
8e29ebe
·
verified ·
1 Parent(s): 3d4ac37

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +55 -0
index.html CHANGED
@@ -16,6 +16,61 @@
16
  <p>
17
  hello, i got a new dog, i got a new cat
18
  </p>
 
 
 
 
 
 
 
19
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  </body>
21
  </html>
 
16
  <p>
17
  hello, i got a new dog, i got a new cat
18
  </p>
19
+
20
+ <!-- User input -->
21
+ <textarea id="userInput" placeholder="Type your message here"></textarea>
22
+ <button id="sendButton">Send</button>
23
+
24
+ <!-- AI response -->
25
+ <p id="aiResponse"></p>
26
  </div>
27
+
28
+ <script>
29
+ // Replace with your Hugging Face model endpoint
30
+ const transformerAPIUrl = "https://api-inference.huggingface.co/models/electric-otter/AutoV1";
31
+
32
+ // Handle button click event
33
+ document.getElementById('sendButton').addEventListener('click', async function() {
34
+ // Get user input
35
+ const userInput = document.getElementById('userInput').value;
36
+
37
+ // Check if there's input
38
+ if (userInput.trim() === "") {
39
+ alert("Please enter a message.");
40
+ return;
41
+ }
42
+
43
+ // Prepare the request body
44
+ const requestBody = {
45
+ "inputs": userInput
46
+ };
47
+
48
+ // Send POST request to Hugging Face API
49
+ try {
50
+ const response = await fetch(transformerAPIUrl, {
51
+ method: 'POST',
52
+ headers: {
53
+ 'Content-Type': 'application/json',
54
+ // No API key needed for public models
55
+ },
56
+ body: JSON.stringify(requestBody)
57
+ });
58
+
59
+ // Check if the response is successful
60
+ if (!response.ok) {
61
+ throw new Error("Failed to fetch response from API.");
62
+ }
63
+
64
+ // Parse the response from Hugging Face
65
+ const data = await response.json();
66
+
67
+ // Display AI response
68
+ document.getElementById('aiResponse').innerText = "AI says: " + data[0].generated_text;
69
+ } catch (error) {
70
+ console.error("Error:", error);
71
+ document.getElementById('aiResponse').innerText = "Error occurred. Please try again.";
72
+ }
73
+ });
74
+ </script>
75
  </body>
76
  </html>