danosethrus commited on
Commit
e67426f
·
verified ·
1 Parent(s): 09ba767

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +31 -37
index.html CHANGED
@@ -2,65 +2,59 @@
2
  <html lang="en">
3
  <head>
4
  <meta charset="UTF-8">
5
- <title>EthioDocs AI - Final Test</title>
 
6
  <style>
7
- body { font-family: system-ui, sans-serif; max-width: 500px; margin: 50px auto; background: #f9f9f9; padding: 20px; }
8
- .box { background: white; padding: 25px; border-radius: 12px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
9
- textarea { width: 100%; height: 100px; padding: 10px; border: 1px solid #ddd; border-radius: 8px; box-sizing: border-box; }
10
- button { width: 100%; padding: 12px; background: #0070f3; color: white; border: none; border-radius: 8px; margin-top: 10px; cursor: pointer; font-weight: bold; }
11
- button:disabled { background: #ccc; }
12
- #status { font-size: 0.8em; color: #666; margin-top: 10px; }
13
- #output { margin-top: 20px; padding: 15px; background: #f0f0f0; border-radius: 8px; white-space: pre-wrap; min-height: 40px; }
 
14
  </style>
15
  </head>
16
  <body>
17
 
18
- <div class="box">
19
  <h2>🏥 EthioDocs AI</h2>
20
- <textarea id="prompt" placeholder="Ask a medical question..."></textarea>
21
- <button id="askBtn" onclick="askEthioDoc()">Ask the AI</button>
22
- <div id="status">Ready.</div>
23
- <div id="output">Waiting for your question...</div>
24
  </div>
25
 
26
  <script>
27
- async function askEthioDoc() {
28
  const btn = document.getElementById('askBtn');
29
- const status = document.getElementById('status');
30
- const output = document.getElementById('output');
31
- const text = document.getElementById('prompt').value;
32
 
33
- if (!text) return alert("Please type something!");
34
 
 
35
  btn.disabled = true;
36
- status.innerText = "Connecting to Bridge (app.py)...";
37
- output.innerText = "Thinking...";
38
 
39
  try {
40
- // We call the local bridge we built in app.py
41
- const response = await fetch("/ask", {
42
  method: "POST",
43
  headers: { "Content-Type": "application/json" },
44
- body: JSON.stringify({ inputs: text })
45
  });
46
-
47
- const data = await response.json();
48
- btn.disabled = false;
49
-
50
  if (data.error) {
51
- status.innerText = "Server is busy.";
52
- output.innerText = "The model is still starting up. Please wait 15 seconds and try again.";
53
- } else if (Array.isArray(data) && data[0].generated_text) {
54
- status.innerText = "Success!";
55
- output.innerText = data[0].generated_text;
56
  } else {
57
- status.innerText = "Unexpected response.";
58
- output.innerText = JSON.stringify(data);
59
  }
60
- } catch (err) {
 
 
 
61
  btn.disabled = false;
62
- status.innerText = "Bridge Error.";
63
- output.innerText = "Could not reach app.py. Make sure your Space status is 'Running'.";
64
  }
65
  }
66
  </script>
 
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>EthioDocs AI</title>
7
  <style>
8
+ body { font-family: 'Inter', sans-serif; background: #f4f7f6; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; }
9
+ .chat-container { width: 100%; max-width: 450px; background: white; padding: 25px; border-radius: 20px; box-shadow: 0 10px 25px rgba(0,0,0,0.05); }
10
+ h2 { color: #007bff; text-align: center; margin-bottom: 20px; }
11
+ textarea { width: 100%; height: 120px; border: 2px solid #eee; border-radius: 12px; padding: 15px; font-size: 16px; outline: none; transition: border 0.3s; box-sizing: border-box; }
12
+ textarea:focus { border-color: #007bff; }
13
+ button { width: 100%; background: #007bff; color: white; border: none; padding: 15px; border-radius: 12px; font-size: 18px; font-weight: bold; cursor: pointer; margin-top: 15px; transition: transform 0.2s; }
14
+ button:active { transform: scale(0.98); }
15
+ #response { margin-top: 20px; padding: 15px; background: #f8f9fa; border-radius: 12px; font-size: 15px; color: #333; line-height: 1.5; display: none; }
16
  </style>
17
  </head>
18
  <body>
19
 
20
+ <div class="chat-container">
21
  <h2>🏥 EthioDocs AI</h2>
22
+ <textarea id="question" placeholder="Ask me any medical question..."></textarea>
23
+ <button onclick="askAI()" id="askBtn">Consult AI</button>
24
+ <div id="response"></div>
 
25
  </div>
26
 
27
  <script>
28
+ async function askAI() {
29
  const btn = document.getElementById('askBtn');
30
+ const box = document.getElementById('response');
31
+ const input = document.getElementById('question').value;
 
32
 
33
+ if(!input) return;
34
 
35
+ btn.innerText = "Processing...";
36
  btn.disabled = true;
37
+ box.style.display = "block";
38
+ box.innerText = "EthioDoc is analyzing your request...";
39
 
40
  try {
41
+ const res = await fetch("/ask", {
 
42
  method: "POST",
43
  headers: { "Content-Type": "application/json" },
44
+ body: JSON.stringify({ inputs: input })
45
  });
46
+ const data = await res.json();
47
+
 
 
48
  if (data.error) {
49
+ box.innerText = "Model is waking up. Please wait 15 seconds and try again.";
 
 
 
 
50
  } else {
51
+ box.innerText = data[0].generated_text;
 
52
  }
53
+ } catch (e) {
54
+ box.innerText = "Error connecting to the server.";
55
+ } finally {
56
+ btn.innerText = "Consult AI";
57
  btn.disabled = false;
 
 
58
  }
59
  }
60
  </script>