jake2004 commited on
Commit
4df1741
·
verified ·
1 Parent(s): 4fc812c

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +7 -65
index.html CHANGED
@@ -7,77 +7,19 @@
7
  <link rel="stylesheet" href="style.css">
8
  </head>
9
  <body>
10
-
11
  <div class="sidebar">
12
- <h2>AI Chat</h2>
13
- <input type="text" id="api-key" placeholder="Enter API Key">
14
- <button class="glow-btn" id="set-api">Set API Key</button>
15
  </div>
16
-
17
  <div class="chat-container">
18
- <h1 class="chat-header">Chat with AI</h1>
19
- <div class="chat-box" id="chat-box"></div>
20
  <div class="chat-input">
21
  <input type="text" id="user-input" placeholder="Type a message...">
22
- <button class="send-btn" id="send-button">Send</button>
23
  </div>
24
  </div>
25
-
26
- <script>
27
- let apiKey = "";
28
-
29
- document.getElementById("set-api").addEventListener("click", () => {
30
- apiKey = document.getElementById("api-key").value.trim();
31
- if (!apiKey) {
32
- alert("Please enter a valid API key.");
33
- }
34
- });
35
-
36
- async function getChatResponse(userMessage) {
37
- if (!apiKey) {
38
- return "API key is missing. Please enter a valid API key.";
39
- }
40
-
41
- try {
42
- const response = await fetch("https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.2", {
43
- method: "POST",
44
- headers: {
45
- "Authorization": `Bearer ${apiKey}`,
46
- "Content-Type": "application/json"
47
- },
48
- body: JSON.stringify({ inputs: userMessage })
49
- });
50
-
51
- const data = await response.json();
52
- return data.generated_text || "Sorry, I couldn't process your request.";
53
- } catch (error) {
54
- console.error("Error fetching response:", error);
55
- return "An error occurred. Please try again.";
56
- }
57
- }
58
-
59
- async function handleChat() {
60
- const userInput = document.getElementById("user-input").value;
61
- if (!userInput.trim()) return;
62
-
63
- const chatBox = document.getElementById("chat-box");
64
- chatBox.innerHTML += `<div class="user-message"><strong>You:</strong> ${userInput}</div>`;
65
- document.getElementById("user-input").value = "";
66
-
67
- const response = await getChatResponse(userInput);
68
- chatBox.innerHTML += `<div class="bot-message"><strong>AI:</strong> ${response}</div>`;
69
-
70
- chatBox.scrollTop = chatBox.scrollHeight;
71
- }
72
-
73
- document.getElementById("user-input").addEventListener("keypress", function (event) {
74
- if (event.key === "Enter") {
75
- handleChat();
76
- }
77
- });
78
-
79
- document.getElementById("send-button").addEventListener("click", handleChat);
80
- </script>
81
-
82
  </body>
83
  </html>
 
7
  <link rel="stylesheet" href="style.css">
8
  </head>
9
  <body>
 
10
  <div class="sidebar">
11
+ <h2>Chatbot</h2>
12
+ <input type="text" id="api-key" placeholder="Enter API Key" class="api-input">
13
+ <button class="glow-btn" onclick="setApiKey()">Set API Key</button>
14
  </div>
 
15
  <div class="chat-container">
16
+ <h1 class="chat-header">AI Chat</h1>
17
+ <div id="chat-box" class="chat-box"></div>
18
  <div class="chat-input">
19
  <input type="text" id="user-input" placeholder="Type a message...">
20
+ <button id="send-button" class="send-btn">Send</button>
21
  </div>
22
  </div>
23
+ <script src="script.js"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  </body>
25
  </html>