jake2004 commited on
Commit
fa4cdcb
·
verified ·
1 Parent(s): 6ef8cc7

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +104 -22
index.html CHANGED
@@ -5,17 +5,105 @@
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>AI Chatbot</title>
7
  <script type="module" src="https://cdn.jsdelivr.net/npm/@huggingface/inference"></script>
8
- <link rel="stylesheet" href="style.css">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  </head>
10
  <body>
11
 
12
- <div id="api-key-container" class="api-key-container">
13
  <h2>Enter Your Hugging Face API Key</h2>
14
- <input type="text" id="api-key-input" placeholder="hf_xxxxxxxxxxxxxxxxxxxx">
15
- <button id="submit-api-key">Submit</button>
16
  </div>
17
 
18
- <div class="chat-container" id="chat-container" style="display: none;">
19
  <div class="chat-box" id="chat-box"></div>
20
  <div class="input-container">
21
  <input type="text" id="user-input" placeholder="Type your message...">
@@ -26,25 +114,21 @@
26
  <script type="module">
27
  import { HfInference } from "https://cdn.jsdelivr.net/npm/@huggingface/inference";
28
 
29
- let hfApiKey = "";
30
-
31
- document.getElementById("submit-api-key").addEventListener("click", () => {
32
- hfApiKey = document.getElementById("api-key-input").value.trim();
33
- console.log("API Key Entered:", hfApiKey); // Debugging log
34
-
35
- if (hfApiKey.startsWith("hf_")) {
36
- document.getElementById("api-key-container").style.display = "none";
37
- document.getElementById("chat-container").style.display = "flex";
38
- console.log("Chat UI should be visible now");
39
- } else {
40
- alert("Invalid API Key! Please enter a valid Hugging Face API key.");
41
- }
42
- });
43
 
 
 
 
 
 
 
 
 
 
 
44
 
45
  async function getChatResponse(userMessage) {
46
  try {
47
- const client = new HfInference(hfApiKey);
48
  const chatCompletion = await client.chatCompletion({
49
  model: "mistralai/Mistral-7B-Instruct-v0.2",
50
  messages: [{ role: "user", content: userMessage }],
@@ -81,11 +165,9 @@
81
  chatBox.innerHTML += `<div class="user-message"><strong>You:</strong> ${userInput}</div>`;
82
  document.getElementById("user-input").value = "";
83
 
84
- // Get AI response
85
  const response = await getChatResponse(userInput);
86
  chatBox.innerHTML += `<div class="bot-message"><strong>AI:</strong> ${response}</div>`;
87
 
88
- // Get Wikipedia image
89
  const imageUrl = await getWikipediaImage(userInput);
90
  if (imageUrl) {
91
  chatBox.innerHTML += `<div class="bot-message"><strong>Related Image:</strong><br><img src="${imageUrl}" alt="Wikipedia Image"></div>`;
 
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>AI Chatbot</title>
7
  <script type="module" src="https://cdn.jsdelivr.net/npm/@huggingface/inference"></script>
8
+ <style>
9
+ body {
10
+ font-family: Arial, sans-serif;
11
+ background-color: #121212;
12
+ color: white;
13
+ display: flex;
14
+ justify-content: center;
15
+ align-items: center;
16
+ height: 100vh;
17
+ margin: 0;
18
+ }
19
+ .chat-container {
20
+ width: 400px;
21
+ background: #1e1e1e;
22
+ border-radius: 10px;
23
+ box-shadow: 0px 0px 15px rgba(255, 255, 255, 0.1);
24
+ overflow: hidden;
25
+ display: none;
26
+ }
27
+ .api-container {
28
+ text-align: center;
29
+ padding: 20px;
30
+ }
31
+ .api-container input {
32
+ padding: 10px;
33
+ width: 80%;
34
+ border: none;
35
+ border-radius: 5px;
36
+ font-size: 16px;
37
+ }
38
+ .api-container button {
39
+ padding: 10px;
40
+ margin-top: 10px;
41
+ background: #4caf50;
42
+ color: white;
43
+ border: none;
44
+ border-radius: 5px;
45
+ cursor: pointer;
46
+ }
47
+ .chat-box {
48
+ height: 400px;
49
+ overflow-y: auto;
50
+ padding: 15px;
51
+ }
52
+ .user-message, .bot-message {
53
+ background: #333;
54
+ padding: 10px;
55
+ margin: 5px 0;
56
+ border-radius: 8px;
57
+ max-width: 80%;
58
+ }
59
+ .user-message {
60
+ align-self: flex-end;
61
+ background: #4caf50;
62
+ color: white;
63
+ }
64
+ .bot-message {
65
+ align-self: flex-start;
66
+ }
67
+ img {
68
+ width: 100%;
69
+ max-width: 250px;
70
+ border-radius: 10px;
71
+ margin-top: 5px;
72
+ }
73
+ .input-container {
74
+ display: flex;
75
+ padding: 10px;
76
+ background: #282828;
77
+ }
78
+ input {
79
+ flex: 1;
80
+ padding: 10px;
81
+ border: none;
82
+ border-radius: 5px;
83
+ font-size: 16px;
84
+ }
85
+ button {
86
+ padding: 10px;
87
+ background: #4caf50;
88
+ color: white;
89
+ border: none;
90
+ border-radius: 5px;
91
+ cursor: pointer;
92
+ }
93
+ button:hover {
94
+ background: #45a049;
95
+ }
96
+ </style>
97
  </head>
98
  <body>
99
 
100
+ <div class="api-container" id="api-container">
101
  <h2>Enter Your Hugging Face API Key</h2>
102
+ <input type="text" id="api-key-input" placeholder="Enter API Key...">
103
+ <button id="api-submit">Submit</button>
104
  </div>
105
 
106
+ <div class="chat-container" id="chat-container">
107
  <div class="chat-box" id="chat-box"></div>
108
  <div class="input-container">
109
  <input type="text" id="user-input" placeholder="Type your message...">
 
114
  <script type="module">
115
  import { HfInference } from "https://cdn.jsdelivr.net/npm/@huggingface/inference";
116
 
117
+ let client = null;
 
 
 
 
 
 
 
 
 
 
 
 
 
118
 
119
+ document.getElementById("api-submit").addEventListener("click", function () {
120
+ const apiKey = document.getElementById("api-key-input").value.trim();
121
+ if (!apiKey) {
122
+ alert("Please enter a valid API key.");
123
+ return;
124
+ }
125
+ client = new HfInference(apiKey);
126
+ document.getElementById("api-container").style.display = "none";
127
+ document.getElementById("chat-container").style.display = "block";
128
+ });
129
 
130
  async function getChatResponse(userMessage) {
131
  try {
 
132
  const chatCompletion = await client.chatCompletion({
133
  model: "mistralai/Mistral-7B-Instruct-v0.2",
134
  messages: [{ role: "user", content: userMessage }],
 
165
  chatBox.innerHTML += `<div class="user-message"><strong>You:</strong> ${userInput}</div>`;
166
  document.getElementById("user-input").value = "";
167
 
 
168
  const response = await getChatResponse(userInput);
169
  chatBox.innerHTML += `<div class="bot-message"><strong>AI:</strong> ${response}</div>`;
170
 
 
171
  const imageUrl = await getWikipediaImage(userInput);
172
  if (imageUrl) {
173
  chatBox.innerHTML += `<div class="bot-message"><strong>Related Image:</strong><br><img src="${imageUrl}" alt="Wikipedia Image"></div>`;