Spaces:
Running
Running
Delete index.html
Browse files- index.html +0 -195
index.html
DELETED
|
@@ -1,195 +0,0 @@
|
|
| 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>AI Chatbot</title>
|
| 7 |
-
<style>
|
| 8 |
-
* {
|
| 9 |
-
margin: 0;
|
| 10 |
-
padding: 0;
|
| 11 |
-
box-sizing: border-box;
|
| 12 |
-
font-family: 'Poppins', sans-serif;
|
| 13 |
-
}
|
| 14 |
-
body {
|
| 15 |
-
display: flex;
|
| 16 |
-
background: linear-gradient(135deg, #141e30, #243b55);
|
| 17 |
-
height: 100vh;
|
| 18 |
-
color: white;
|
| 19 |
-
justify-content: center;
|
| 20 |
-
align-items: center;
|
| 21 |
-
flex-direction: column;
|
| 22 |
-
padding: 20px;
|
| 23 |
-
}
|
| 24 |
-
.container {
|
| 25 |
-
width: 90%;
|
| 26 |
-
max-width: 600px;
|
| 27 |
-
background: rgba(255, 255, 255, 0.1);
|
| 28 |
-
backdrop-filter: blur(15px);
|
| 29 |
-
padding: 20px;
|
| 30 |
-
border-radius: 12px;
|
| 31 |
-
box-shadow: 0 0 20px rgba(255, 255, 255, 0.2);
|
| 32 |
-
text-align: center;
|
| 33 |
-
}
|
| 34 |
-
.chat-box {
|
| 35 |
-
height: 300px;
|
| 36 |
-
overflow-y: auto;
|
| 37 |
-
padding: 10px;
|
| 38 |
-
border-radius: 10px;
|
| 39 |
-
background: rgba(255, 255, 255, 0.2);
|
| 40 |
-
}
|
| 41 |
-
.user-message, .bot-message {
|
| 42 |
-
padding: 12px;
|
| 43 |
-
border-radius: 10px;
|
| 44 |
-
margin: 10px 0;
|
| 45 |
-
max-width: 75%;
|
| 46 |
-
word-wrap: break-word;
|
| 47 |
-
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
|
| 48 |
-
}
|
| 49 |
-
.user-message {
|
| 50 |
-
align-self: flex-end;
|
| 51 |
-
background: linear-gradient(135deg, #ff758c, #ff7eb3);
|
| 52 |
-
}
|
| 53 |
-
.bot-message {
|
| 54 |
-
align-self: flex-start;
|
| 55 |
-
background: linear-gradient(135deg, #36d1dc, #5b86e5);
|
| 56 |
-
}
|
| 57 |
-
.chat-input {
|
| 58 |
-
display: flex;
|
| 59 |
-
margin-top: 15px;
|
| 60 |
-
}
|
| 61 |
-
.chat-input input {
|
| 62 |
-
flex-grow: 1;
|
| 63 |
-
padding: 12px;
|
| 64 |
-
border-radius: 8px;
|
| 65 |
-
border: none;
|
| 66 |
-
outline: none;
|
| 67 |
-
background: rgba(255, 255, 255, 0.2);
|
| 68 |
-
color: white;
|
| 69 |
-
}
|
| 70 |
-
.send-btn {
|
| 71 |
-
padding: 12px 18px;
|
| 72 |
-
margin-left: 10px;
|
| 73 |
-
background: linear-gradient(45deg, #6a11cb, #2575fc);
|
| 74 |
-
color: white;
|
| 75 |
-
border: none;
|
| 76 |
-
border-radius: 8px;
|
| 77 |
-
cursor: pointer;
|
| 78 |
-
transition: 0.3s;
|
| 79 |
-
}
|
| 80 |
-
.send-btn:hover {
|
| 81 |
-
background: linear-gradient(45deg, #2575fc, #6a11cb);
|
| 82 |
-
}
|
| 83 |
-
.image-container img {
|
| 84 |
-
width: 100%;
|
| 85 |
-
border-radius: 8px;
|
| 86 |
-
box-shadow: 0 4px 8px rgba(255, 255, 255, 0.3);
|
| 87 |
-
}
|
| 88 |
-
@media (max-width: 768px) {
|
| 89 |
-
.container {
|
| 90 |
-
width: 100%;
|
| 91 |
-
padding: 15px;
|
| 92 |
-
}
|
| 93 |
-
.chat-box {
|
| 94 |
-
height: 250px;
|
| 95 |
-
}
|
| 96 |
-
}
|
| 97 |
-
</style>
|
| 98 |
-
</head>
|
| 99 |
-
<body>
|
| 100 |
-
<div class="container">
|
| 101 |
-
<h2>AI Chatbot</h2>
|
| 102 |
-
<input type="text" id="chat-api-key" placeholder="Enter Hugging Face API Key (Chat)" style="width: 100%; padding: 10px; margin-bottom: 10px; border-radius: 5px;">
|
| 103 |
-
<input type="text" id="image-api-key" placeholder="Enter Hugging Face API Key (Image)" style="width: 100%; padding: 10px; margin-bottom: 10px; border-radius: 5px;">
|
| 104 |
-
|
| 105 |
-
<div class="chat-box" id="chat-box"></div>
|
| 106 |
-
|
| 107 |
-
<div class="chat-input">
|
| 108 |
-
<input type="text" id="user-input" placeholder="Type a message...">
|
| 109 |
-
<button class="send-btn" id="send-button">Send</button>
|
| 110 |
-
</div>
|
| 111 |
-
|
| 112 |
-
<div class="image-container" id="image-container"></div>
|
| 113 |
-
</div>
|
| 114 |
-
|
| 115 |
-
<script type="module">
|
| 116 |
-
import { HfInference } from "https://cdn.jsdelivr.net/npm/@huggingface/inference/+esm";
|
| 117 |
-
|
| 118 |
-
let chatClient, imageClient;
|
| 119 |
-
|
| 120 |
-
document.getElementById("send-button").addEventListener("click", handleChat);
|
| 121 |
-
document.getElementById("user-input").addEventListener("keypress", function(event) {
|
| 122 |
-
if (event.key === "Enter") handleChat();
|
| 123 |
-
});
|
| 124 |
-
|
| 125 |
-
async function handleChat() {
|
| 126 |
-
const userInput = document.getElementById("user-input").value;
|
| 127 |
-
const chatApiKey = document.getElementById("chat-api-key").value;
|
| 128 |
-
const imageApiKey = document.getElementById("image-api-key").value;
|
| 129 |
-
if (!userInput.trim() || !chatApiKey.trim() || !imageApiKey.trim()) return;
|
| 130 |
-
|
| 131 |
-
if (!chatClient) chatClient = new HfInference(chatApiKey);
|
| 132 |
-
if (!imageClient) imageClient = new HfInference(imageApiKey);
|
| 133 |
-
|
| 134 |
-
const chatBox = document.getElementById("chat-box");
|
| 135 |
-
chatBox.innerHTML += `<div class='user-message'><strong>You:</strong> ${userInput}</div>`;
|
| 136 |
-
document.getElementById("user-input").value = "";
|
| 137 |
-
|
| 138 |
-
if (userInput.toLowerCase().startsWith("generate an image of")) {
|
| 139 |
-
const imagePrompt = userInput.replace("generate an image of", "").trim();
|
| 140 |
-
await generateImage(imagePrompt);
|
| 141 |
-
} else {
|
| 142 |
-
await fetchChatResponse(userInput);
|
| 143 |
-
}
|
| 144 |
-
chatBox.scrollTop = chatBox.scrollHeight;
|
| 145 |
-
}
|
| 146 |
-
|
| 147 |
-
async function fetchChatResponse(input) {
|
| 148 |
-
try {
|
| 149 |
-
const response = await chatClient.chatCompletion({
|
| 150 |
-
model: "mistralai/Mistral-7B-Instruct-v0.2",
|
| 151 |
-
messages: [{ role: "user", content: input }],
|
| 152 |
-
max_tokens: 500,
|
| 153 |
-
});
|
| 154 |
-
const botMessage = response.choices[0].message.content;
|
| 155 |
-
document.getElementById("chat-box").innerHTML += `<div class='bot-message'><strong>VarunGPT-3:</strong> ${botMessage}</div>`;
|
| 156 |
-
} catch (error) {
|
| 157 |
-
console.error("Error fetching chat response:", error);
|
| 158 |
-
}
|
| 159 |
-
}
|
| 160 |
-
|
| 161 |
-
async function generateImage(prompt) {
|
| 162 |
-
const imageContainer = document.getElementById("image-container");
|
| 163 |
-
imageContainer.innerHTML = `<p>Generating image...</p>`;
|
| 164 |
-
|
| 165 |
-
try {
|
| 166 |
-
if (!imageClient) {
|
| 167 |
-
console.error("Hugging Face Image API key is missing.");
|
| 168 |
-
imageContainer.innerHTML = `<p style="color: red;">Error: Missing API Key.</p>`;
|
| 169 |
-
return;
|
| 170 |
-
}
|
| 171 |
-
|
| 172 |
-
const response = await imageClient.textToImage({
|
| 173 |
-
model: "stabilityai/stable-diffusion-xl-base-1.0",
|
| 174 |
-
inputs: prompt,
|
| 175 |
-
parameters: { num_inference_steps: 50, guidance_scale: 7.5 },
|
| 176 |
-
});
|
| 177 |
-
|
| 178 |
-
// Check if the response is a Blob
|
| 179 |
-
if (response instanceof Blob) {
|
| 180 |
-
const imageBlob = response;
|
| 181 |
-
const imageUrl = URL.createObjectURL(imageBlob);
|
| 182 |
-
imageContainer.innerHTML = `<img src="${imageUrl}" alt="Generated Image">`;
|
| 183 |
-
} else {
|
| 184 |
-
console.error("Unexpected response format:", response);
|
| 185 |
-
imageContainer.innerHTML = `<p style="color: red;">Error: Invalid API response.</p>`;
|
| 186 |
-
}
|
| 187 |
-
|
| 188 |
-
} catch (error) {
|
| 189 |
-
console.error("Error generating image:", error.message || error);
|
| 190 |
-
imageContainer.innerHTML = `<p style="color: red;">Error generating image: ${error.message || "Unknown error"}</p>`;
|
| 191 |
-
}
|
| 192 |
-
}
|
| 193 |
-
</script>
|
| 194 |
-
</body>
|
| 195 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|