-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrontend.html
More file actions
181 lines (146 loc) · 4.88 KB
/
Copy pathfrontend.html
File metadata and controls
181 lines (146 loc) · 4.88 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hospital AI Assistant</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
<style>
body {
font-family: 'Inter', sans-serif;
background: linear-gradient(135deg, #0f172a, #1e293b);
}
/* Glass Card */
.glass {
background: rgba(255,255,255,0.08);
backdrop-filter: blur(20px);
border: 1px solid rgba(255,255,255,0.1);
}
/* Animated ring */
.ring {
width: 260px;
height: 260px;
border-radius: 50%;
position: relative;
}
.ring::before {
content: "";
position: absolute;
inset: -8px;
border-radius: 50%;
background: conic-gradient(#6366f1, #ec4899, #6366f1);
filter: blur(25px);
opacity: 0.7;
animation: spin 6s linear infinite;
}
@keyframes spin {
100% { transform: rotate(360deg); }
}
.hidden { display: none; }
</style>
</head>
<body class="h-screen flex items-center justify-center">
<!-- DASHBOARD -->
<div id="dashboard" class="glass p-8 rounded-3xl w-full max-w-md text-white shadow-2xl">
<h1 class="text-2xl font-bold text-center mb-2">🏥 Hospital AI</h1>
<p class="text-center text-gray-300 mb-6">Talk to Sarah (AI Receptionist)</p>
<div class="space-y-4">
<input id="input-name" placeholder="Your Name"
class="w-full p-3 rounded-xl bg-white/10 border border-white/20 focus:outline-none">
<input id="input-email" placeholder="Email"
class="w-full p-3 rounded-xl bg-white/10 border border-white/20 focus:outline-none">
<select id="language-select"
class="w-full p-3 rounded-xl bg-white/10 border border-white/20 text-white">
<option value="en-IN">English</option>
<option value="hi-IN">Hindi</option>
<option value="te-IN">Telugu</option>
</select>
</div>
<button id="start-btn"
class="mt-6 w-full bg-indigo-600 hover:bg-indigo-700 p-3 rounded-xl font-semibold">
🎤 Start Call
</button>
</div>
<!-- CALL SCREEN -->
<div id="call-screen" class="hidden absolute inset-0 flex flex-col items-center justify-center text-white">
<div class="ring flex items-center justify-center">
<i id="status-icon" class="fa-solid fa-microphone text-5xl text-white"></i>
</div>
<p id="agent-status" class="mt-6 text-gray-300">Connecting...</p>
<div id="transcript" class="mt-6 max-w-xl text-center text-lg text-gray-200"></div>
<button id="end-btn"
class="mt-8 bg-red-600 px-6 py-3 rounded-full">
End Call
</button>
</div>
<script>
const API_URL = "http://127.0.0.1:8000";
let sessionId = null;
let recognition = null;
let isRecording = false;
let currentAudio = null;
const dashboard = document.getElementById("dashboard");
const callScreen = document.getElementById("call-screen");
const transcript = document.getElementById("transcript");
const statusText = document.getElementById("agent-status");
const statusIcon = document.getElementById("status-icon");
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
if (SpeechRecognition) {
recognition = new SpeechRecognition();
recognition.onstart = () => {
isRecording = true;
statusText.innerText = "Listening...";
};
recognition.onend = () => {
isRecording = false;
};
recognition.onresult = (e) => {
const text = e.results[0][0].transcript;
transcript.innerText = text;
sendMessage(text);
};
}
document.getElementById("start-btn").onclick = async () => {
dashboard.classList.add("hidden");
callScreen.classList.remove("hidden");
const res = await fetch(API_URL + "/agent/new_session", { method: "POST" });
sessionId = (await res.json()).session_id;
sendMessage("Hello");
};
document.getElementById("end-btn").onclick = () => location.reload();
async function sendMessage(text) {
statusText.innerText = "Thinking...";
const res = await fetch(API_URL + "/agent/message", {
method: "POST",
headers: {"Content-Type": "application/json"},
body: JSON.stringify({
session_id: sessionId,
text: text,
language_code: document.getElementById("language-select").value
})
});
const data = await res.json();
transcript.innerText = data.text;
if (data.audio) {
playAudio(data.audio);
} else {
startListening();
}
}
function playAudio(base64) {
statusText.innerText = "Speaking...";
currentAudio = new Audio("data:audio/mp3;base64," + base64);
currentAudio.onended = () => {
startListening();
};
currentAudio.play();
}
function startListening() {
if (recognition && !isRecording) {
recognition.start();
}
}
</script>
</body>
</html>