File size: 2,254 Bytes
1e7f90f
 
 
22137cd
 
 
1e7f90f
 
22137cd
1e7f90f
 
 
 
22137cd
 
1e7f90f
22137cd
1e7f90f
8e29ebe
 
 
 
 
 
 
1e7f90f
8e29ebe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1e7f90f
 
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
<!doctype html>
<html>
	<head>
      <link rel="preconnect" href="https://fonts.googleapis.com">
      <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
      <link href="https://fonts.googleapis.com/css2?family=Raleway:ital,wght@0,100..900;1,100..900&display=swap" rel="stylesheet">
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width" />
		<title>AutoVChat - talk to AutoV Models</title>
		<link rel="stylesheet" href="style.css" />
	</head>
	<body>
		<div class="card">
			<h1>AutoVChat</h1>
			<p>You can say:</p>
			<p>
				hello, i got a new dog, i got a new cat
			</p>
			
			<!-- User input -->
			<textarea id="userInput" placeholder="Type your message here"></textarea>
			<button id="sendButton">Send</button>

			<!-- AI response -->
			<p id="aiResponse"></p>
		</div>

		<script>
			// Replace with your Hugging Face model endpoint
			const transformerAPIUrl = "https://api-inference.huggingface.co/models/electric-otter/AutoV1";

			// Handle button click event
			document.getElementById('sendButton').addEventListener('click', async function() {
				// Get user input
				const userInput = document.getElementById('userInput').value;
				
				// Check if there's input
				if (userInput.trim() === "") {
					alert("Please enter a message.");
					return;
				}

				// Prepare the request body
				const requestBody = {
					"inputs": userInput
				};

				// Send POST request to Hugging Face API
				try {
					const response = await fetch(transformerAPIUrl, {
						method: 'POST',
						headers: {
							'Content-Type': 'application/json',
							// No API key needed for public models
						},
						body: JSON.stringify(requestBody)
					});

					// Check if the response is successful
					if (!response.ok) {
						throw new Error("Failed to fetch response from API.");
					}

					// Parse the response from Hugging Face
					const data = await response.json();

					// Display AI response
					document.getElementById('aiResponse').innerText = "AI says: " + data[0].generated_text;
				} catch (error) {
					console.error("Error:", error);
					document.getElementById('aiResponse').innerText = "Error occurred. Please try again.";
				}
			});
		</script>
	</body>
</html>