-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdemo.html
More file actions
76 lines (62 loc) · 3.27 KB
/
demo.html
File metadata and controls
76 lines (62 loc) · 3.27 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Toolhouse demo</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
</head>
<body class="text-center">
<h1 class="text-center">
<img style="height:1.3em;position:relative;left:0.1em;bottom:0.1em;" src="https://github.com/CharlesCreativeContent/myImages/blob/main/images/pet_advice_logo.png?raw=true">
Pet Guru
</h1>
<a href="https://www.canva.com/design/DAGQuHYK3pg/ADfxZiNf3ys84vHOvvU2Jw/watch?utm_content=DAGQuHYK3pg&utm_campaign=designshare&utm_medium=link&utm_source=editor" target="_blank"><button class="btn btn-outline-primary" text-center>Demo Video</button></a>
<a href="http://127.0.0.1:8000/docs" target="_blank"><button class="btn btn-outline-primary text-center">API (SwaggerUI)</button></a>
<a href="https://github.com/CharlesCreativeContent/toolhouse-examples" target="_blank"><button class="btn btn-outline-primary text-center">Documentation</button></a>
<br>
<img class="text-center" src="https://github.com/CharlesCreativeContent/myImages/blob/main/images/pet_guru.png?raw=true" alt="Cartoon of a Puppy Therapist and Surprised Owner">
<div class="input-group mb-3 text-center" style="width:50%;margin-left:25%;">
<input type="text" class="form-control text-center" placeholder="How can we help your pet?" aria-label="Recipient's question" aria-describedby="button-addon2">
<button class="btn btn-primary" type="button" id="submit" onclick="pet_advice()">Submit</button>
</div>
<div style="width:50%;margin-left:25%;" id="chatWindow" ></div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
</body>
<script>
let inputForm = document.getElementsByTagName("input")[0]
let submitButton = document.getElementById("submit")
let chatWindow = document.getElementById("chatWindow")
</script>
<script>
console.clear()
let pet_advice = () => {
// Grab the user input
let customerInput = inputForm.value
// Clear input and chatwindow
inputForm.value = ""
chatWindow.innerHTML = ""
// start spinner
submitButton.disabled = true
submitButton.innerHTML = `
<span class="spinner-border spinner-border-sm" aria-hidden="true"></span>
<span role="status">Loading...</span>
`
// Request pet advice
fetch('http://127.0.0.1:8000/pets', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({message: customerInput})
})
.then(response => response.json())
.then(data => {
console.log(data)
// update chatWindow and stop spinner
chatWindow.innerHTML = data.received_messages
document.getElementById("submit").innerHTML = `Submit`
submitButton.disabled = false
})
.catch(error => console.error('Error:', error));
}
</script>
</html>