Zwea Htet commited on
Commit
6288a82
·
1 Parent(s): 8042ffc

fixed bugs

Browse files
Files changed (5) hide show
  1. index.json +0 -0
  2. main.py +5 -1
  3. static/script.js +4 -5
  4. templates/base.html +0 -1
  5. templates/chat.html +2 -2
index.json CHANGED
The diff for this file is too large to render. See raw diff
 
main.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import os
2
 
3
  import openai
@@ -23,15 +24,18 @@ app.mount("/static", StaticFiles(directory="static", html=True), name="static")
23
  # with the dialog form the user and bot
24
  templates = Jinja2Templates(directory="templates")
25
 
 
 
26
  @app.get("/", response_class=HTMLResponse)
27
  async def home(request: Request):
28
  return templates.TemplateResponse('chat.html', {"request": request})
29
 
30
  @app.get("/chat")
31
  async def chat(input: str):
 
32
  bot_reply = index.query(input)
33
  return {"bot_reply": bot_reply}
34
 
35
  if __name__ == "__main__":
36
- index = initialize_index("index.json")
37
  uvicorn.run("main:app", reload=True)
 
1
+ import datetime
2
  import os
3
 
4
  import openai
 
24
  # with the dialog form the user and bot
25
  templates = Jinja2Templates(directory="templates")
26
 
27
+ index = initialize_index("index.json")
28
+
29
  @app.get("/", response_class=HTMLResponse)
30
  async def home(request: Request):
31
  return templates.TemplateResponse('chat.html', {"request": request})
32
 
33
  @app.get("/chat")
34
  async def chat(input: str):
35
+ print("input: ", input)
36
  bot_reply = index.query(input)
37
  return {"bot_reply": bot_reply}
38
 
39
  if __name__ == "__main__":
40
+ # index = initialize_index("index.json")
41
  uvicorn.run("main:app", reload=True)
static/script.js CHANGED
@@ -3,7 +3,7 @@ const msgerInput = get(".msger-input");
3
  const msgerChat = get(".msger-chat");
4
 
5
  // Icons made by Freepik from www.flaticon.com
6
- const BOT_IMG = "./icons/dialogflow-insights-svgrepo-com.svg";
7
  const PERSON_IMG = "";
8
  const BOT_NAME = " ChatBot";
9
  const PERSON_NAME = "You";
@@ -24,7 +24,6 @@ function appendMessage(name, img, side, text) {
24
  const msgHTML = `
25
  <div class="msg ${side}-msg">
26
  <div class="msg-img" style="background-image: url(${img})"></div>
27
-
28
  <div class="msg-bubble">
29
  <div class="msg-info">
30
  <div class="msg-info-name">${name}</div>
@@ -44,13 +43,13 @@ function appendMessage(name, img, side, text) {
44
 
45
  async function botResponse(text) {
46
  // Bot Response
47
- const response = await fetch("chat?input=${text}");
 
48
  const json = await response.json();
49
 
50
- console.log(text);
51
  console.log(json);
52
 
53
- appendMessage(BOT_NAME, BOT_IMG, "left", json.bot_reply);
54
  }
55
 
56
  // Utils
 
3
  const msgerChat = get(".msger-chat");
4
 
5
  // Icons made by Freepik from www.flaticon.com
6
+ const BOT_IMG = "../static/icons/dialogflow-insights-svgrepo-com.svg";
7
  const PERSON_IMG = "";
8
  const BOT_NAME = " ChatBot";
9
  const PERSON_NAME = "You";
 
24
  const msgHTML = `
25
  <div class="msg ${side}-msg">
26
  <div class="msg-img" style="background-image: url(${img})"></div>
 
27
  <div class="msg-bubble">
28
  <div class="msg-info">
29
  <div class="msg-info-name">${name}</div>
 
43
 
44
  async function botResponse(text) {
45
  // Bot Response
46
+ console.log(text);
47
+ const response = await fetch(`chat?input=${text}`);
48
  const json = await response.json();
49
 
 
50
  console.log(json);
51
 
52
+ appendMessage(BOT_NAME, BOT_IMG, "left", json.bot_reply.response);
53
  }
54
 
55
  // Utils
templates/base.html CHANGED
@@ -8,7 +8,6 @@
8
  <title>{% block title %}{% endblock %}</title>
9
  <link rel="stylesheet" href="{{ url_for('static', path='styles/chat.css') }}">
10
  <link rel="stylesheet" href="{{ url_for('static', path='styles/login.css') }}">
11
- <!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> -->
12
  <script type="module" src="../static/script.js"></script>
13
  </head>
14
 
 
8
  <title>{% block title %}{% endblock %}</title>
9
  <link rel="stylesheet" href="{{ url_for('static', path='styles/chat.css') }}">
10
  <link rel="stylesheet" href="{{ url_for('static', path='styles/login.css') }}">
 
11
  <script type="module" src="../static/script.js"></script>
12
  </head>
13
 
templates/chat.html CHANGED
@@ -13,13 +13,13 @@
13
 
14
  <main class="msger-chat">
15
  <div class="msg left-msg">
16
- <div class="msg-img" style="background-image: url(https://image.flaticon.com/icons/svg/327/327779.svg)">
17
  </div>
18
 
19
  <div class="msg-bubble">
20
  <div class="msg-info">
21
  <div class="msg-info-name">Chatbot</div>
22
- <div class="msg-info-time">{}</div>
23
  </div>
24
 
25
  <div class="msg-text">
 
13
 
14
  <main class="msger-chat">
15
  <div class="msg left-msg">
16
+ <div class="msg-img" style="background-image: url(../static/icons/dialogflow-insights-svgrepo-com.svg)">
17
  </div>
18
 
19
  <div class="msg-bubble">
20
  <div class="msg-info">
21
  <div class="msg-info-name">Chatbot</div>
22
+ <div class="msg-info-time">${}</div>
23
  </div>
24
 
25
  <div class="msg-text">