-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatbot.html
More file actions
157 lines (141 loc) · 4.37 KB
/
chatbot.html
File metadata and controls
157 lines (141 loc) · 4.37 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<!DOCTYPE html>
<html lang="en">
<head>
<title>Ecowatt AI Chatbot</title>
<script src="https://unpkg.com/typewriter-effect@latest/dist/core.js"></script>
<script src="https://cdn.jsdelivr.net/npm/axios@1.1.2/dist/axios.min.js"></script>
<style>
/* General Styles */
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-image: url("n1.jpeg");
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
text-align: center;
}
/* Header Styling */
header {
background: linear-gradient(to right, #0b4f56, #4ea398);
color: white;
padding: 20px;
font-size: 24px;
font-weight: bold;
border-bottom-left-radius: 40px;
border-bottom-right-radius: 40px;
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
}
/* Navigation Styling */
nav {
display: flex;
gap: 20px;
}
nav a {
color: white;
text-decoration: none;
font-weight: bold;
padding: 10px 15px;
background: linear-gradient(to right, #046b74, #08959d);
border-radius: 8px;
font-size: 16px;
transition: transform 0.2s ease, background 0.3s ease-in-out;
box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.3);
}
nav a:hover {
background: linear-gradient(to right, #08959d, #046b74);
transform: scale(1.1);
box-shadow: 0px 6px 12px rgba(0, 0, 0, 0.4);
}
/* Center Chatbot Container */
.chat-container {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 350px;
background: white;
border-radius: 10px;
padding: 15px;
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.2);
}
/* Chat Output */
#chat-output {
max-height: 300px;
overflow-y: auto;
padding: 10px;
border-bottom: 1px solid #ddd;
text-align: left;
}
/* Chat Input */
#user-question {
width: 75%;
padding: 8px;
border: 1px solid #ccc;
border-radius: 5px;
}
/* Send Button */
#send-btn {
background: #074952;
color: white;
border: none;
padding: 8px 15px;
cursor: pointer;
border-radius: 5px;
}
#send-btn:hover {
background: #046b74;
}
</style>
</head>
<body>
<header>
<h1>Ask Ecowatt AI</h1>
<nav>
<a href="index.html">Home</a>
<a href="about.html">About</a>
<a href="tutorials.html">Tutorials</a>
</nav>
</header>
<div class="chat-container">
<div id="chat-output"></div>
<form id="chat-form">
<input
type="text"
id="user-question"
placeholder="Ask me about renewable energy..."
required
/>
<button id="send-btn">Send</button>
</form>
</div>
<script>
function displayResponse(response) {
new Typewriter("#chat-output", {
strings: response.data.answer,
autoStart: true,
delay: 1,
cursor: "",
});
}
function chatWithAI(event) {
event.preventDefault();
let userInput = document.querySelector("#user-question");
let apiKey = "2046c535afeb092fo82f1d306d8a2b2t"; // Replace with your actual API key
let context =
"You are an AI assistant specializing in renewable energy and sustainability. Your goal is to provide informative, engaging, and easy-to-understand answers about solar, wind, and hydro energy. Keep responses concise, factual, and interactive. Avoid technical jargon unless necessary.";
let prompt = `User question: ${userInput.value}`;
let apiURL = `https://api.shecodes.io/ai/v1/generate?prompt=${prompt}&context=${context}&key=${apiKey}`;
let chatOutput = document.querySelector("#chat-output");
chatOutput.innerHTML += `<div class="generating">⏳ Thinking... Answering: "${userInput.value}"</div>`;
axios.get(apiURL).then(displayResponse);
}
let chatFormElement = document.querySelector("#chat-form");
chatFormElement.addEventListener("submit", chatWithAI);
</script>
</body>
</html>