ayush2917 commited on
Commit
3a9bf57
·
verified ·
1 Parent(s): 57e80b0

Update templates/chat.html

Browse files
Files changed (1) hide show
  1. templates/chat.html +8 -60
templates/chat.html CHANGED
@@ -1,70 +1,18 @@
1
  {% extends "base.html" %}
2
 
 
 
 
 
 
 
3
  {% block content %}
4
  <div class="container">
5
- <div class="chat-container">
6
  <h1>Chat with Little Krishna</h1>
7
-
8
- {% if chat_history %}
9
- <div class="chat-history">
10
- {% for message in chat_history %}
11
- <p><strong>You:</strong> {{ message.user_input }}</p>
12
- <p><strong>Krishna:</strong> {{ message.reply }}</p>
13
- {% endfor %}
14
- </div>
15
- {% else %}
16
- <p class="chat-error">Error loading chat—try again</p>
17
- {% endif %}
18
-
19
- <div class="chat-options">
20
- <button onclick="sendMessage('Say something to Krishna...')">Say Something</button>
21
- <button onclick="sendMessage('Tell me a story!')">Tell a Story</button>
22
- <button onclick="sendMessage('Tell me a riddle!')">Tell a Riddle</button>
23
- </div>
24
-
25
- <div class="chat-input">
26
- <input type="text" id="message-input" placeholder="Type your message here..." />
27
- <button onclick="sendMessage(document.getElementById('message-input').value)">Send</button>
28
- </div>
29
- </div>
30
  </div>
31
  {% endblock %}
32
 
33
  {% block scripts %}
34
- <script>
35
- async function sendMessage(message) {
36
- if (!message) return;
37
-
38
- const response = await fetch('/chat', {
39
- method: 'POST',
40
- headers: {
41
- 'Content-Type': 'application/x-www-form-urlencoded',
42
- },
43
- body: new URLSearchParams({ 'message': message })
44
- });
45
-
46
- const data = await response.json();
47
- if (data.reply) {
48
- const chatHistory = document.querySelector('.chat-history') || document.createElement('div');
49
- if (!chatHistory.classList.contains('chat-history')) {
50
- chatHistory.classList.add('chat-history');
51
- document.querySelector('.chat-container').insertBefore(chatHistory, document.querySelector('.chat-options'));
52
- }
53
- chatHistory.innerHTML += `<p><strong>You:</strong> ${message}</p>`;
54
- chatHistory.innerHTML += `<p><strong>Krishna:</strong> ${data.reply}</p>`;
55
- chatHistory.scrollTop = chatHistory.scrollHeight;
56
-
57
- // Remove error message if present
58
- const errorMessage = document.querySelector('.chat-error');
59
- if (errorMessage) {
60
- errorMessage.remove();
61
- }
62
- } else {
63
- alert('Error: Could not get a response from Krishna. Please try again.');
64
- }
65
-
66
- // Clear the input field
67
- document.getElementById('message-input').value = '';
68
- }
69
- </script>
70
  {% endblock %}
 
1
  {% extends "base.html" %}
2
 
3
+ {% block title %}Chat with Krishna{% endblock %}
4
+
5
+ {% block styles %}
6
+ <link rel="stylesheet" href="{{ url_for('static', filename='css/chat.css') }}">
7
+ {% endblock %}
8
+
9
  {% block content %}
10
  <div class="container">
 
11
  <h1>Chat with Little Krishna</h1>
12
+ <p>Chat functionality to be implemented.</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  </div>
14
  {% endblock %}
15
 
16
  {% block scripts %}
17
+ <script src="{{ url_for('static', filename='js/chat.js') }}"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  {% endblock %}