Latest5
Browse files- app.py +2 -0
- static/chat.html +52 -0
app.py
CHANGED
@@ -9,7 +9,9 @@ from groq import Groq
|
|
9 |
from starlette.middleware.sessions import SessionMiddleware
|
10 |
|
11 |
app = FastAPI()
|
|
|
12 |
|
|
|
13 |
# Secret key for sessions
|
14 |
app.add_middleware(SessionMiddleware, secret_key=os.urandom(24))
|
15 |
|
|
|
9 |
from starlette.middleware.sessions import SessionMiddleware
|
10 |
|
11 |
app = FastAPI()
|
12 |
+
from fastapi.staticfiles import StaticFiles
|
13 |
|
14 |
+
app.mount("/static", StaticFiles(directory="."), name="static")
|
15 |
# Secret key for sessions
|
16 |
app.add_middleware(SessionMiddleware, secret_key=os.urandom(24))
|
17 |
|
static/chat.html
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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>Chat with Amara</title>
|
7 |
+
<style>
|
8 |
+
body { font-family: Arial, sans-serif; }
|
9 |
+
#chat-box { border: 1px solid #ccc; padding: 10px; margin: 20px; height: 400px; overflow-y: scroll; }
|
10 |
+
#user-input { margin: 20px; }
|
11 |
+
</style>
|
12 |
+
</head>
|
13 |
+
<body>
|
14 |
+
|
15 |
+
<h1>Chat with Amara</h1>
|
16 |
+
<div id="chat-box"></div>
|
17 |
+
<div id="user-input">
|
18 |
+
<input type="text" id="message" placeholder="Type your message here..." />
|
19 |
+
<button onclick="sendMessage()">Send</button>
|
20 |
+
</div>
|
21 |
+
|
22 |
+
<script>
|
23 |
+
async function sendMessage() {
|
24 |
+
const messageInput = document.getElementById('message');
|
25 |
+
const message = messageInput.value;
|
26 |
+
messageInput.value = '';
|
27 |
+
|
28 |
+
// Display the user's message
|
29 |
+
addMessage(`You: ${message}`);
|
30 |
+
|
31 |
+
// Send the message to the chatbot
|
32 |
+
const response = await fetch('/chat', {
|
33 |
+
method: 'POST',
|
34 |
+
headers: {
|
35 |
+
'Content-Type': 'application/json',
|
36 |
+
},
|
37 |
+
body: JSON.stringify({ message })
|
38 |
+
});
|
39 |
+
|
40 |
+
const data = await response.json();
|
41 |
+
addMessage(`Amara: ${data.response}`);
|
42 |
+
}
|
43 |
+
|
44 |
+
function addMessage(message) {
|
45 |
+
const chatBox = document.getElementById('chat-box');
|
46 |
+
chatBox.innerHTML += `<div>${message}</div>`;
|
47 |
+
chatBox.scrollTop = chatBox.scrollHeight; // Scroll to the bottom
|
48 |
+
}
|
49 |
+
</script>
|
50 |
+
|
51 |
+
</body>
|
52 |
+
</html>
|