-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
166 lines (146 loc) · 6.5 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Digital Health Innovator</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
padding-bottom: 60px; /* Add padding to ensure footer doesn't overlap content */
}
.container {
display: inline-block;
text-align: left;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
margin-top: 20px;
margin-right: 10px;
}
.result {
margin-top: 20px;
font-size: 20px;
font-weight: bold;
}
.loading, .error {
color: #666;
font-style: italic;
}
footer {
background-color: #ffcc00;
color: #333;
padding: 10px;
text-align: center;
position: fixed;
bottom: 0;
width: 100%;
z-index: 1000;
}
</style>
</head>
<body>
<div class="container">
<h1>Digital Health Innovator</h1>
<p>Click the buttons to generate your random challenge and technology!</p>
<p>Before hitting the LLM button, please think about your solution with the desired outcome, and <a href="https://yourlinkhere.com" target="_blank">Share Your Solution</a></p>
<button onclick="generateRandom('challenge')">Generate Challenge</button>
<button onclick="generateRandom('technology')">Generate Technology</button>
<button onclick="generateSolution()">Let LLM Generate Solution</button>
<div class="result">
<p id="challenge"></p>
<p id="technology"></p>
<p id="solution"></p>
</div>
</div>
<script>
const SHEET_ID = '1D7Z9Ufzovzw5lP1og5XUnLE3mBZ3FDCFxqYT_O9ITyE';
const API_KEY = 'AIzaSyDgUUIsCwafUEJRlNgNhUk35uve51bPwqU';
const RANGE = 'Sheet1!B2:C';
const LLM_API_KEY = "yiB1Lv5u.sYS6WGo9yqWYPYdRAHN5SnVduBltplVR";
const LLM_URL = "https://payload.vextapp.com/hook/0B0Q4KQUXE/catch/hello";
let challenges = [];
let technologies = [];
let dataFetched = false;
async function fetchFromSheet() {
if (dataFetched) return;
const url = `https://sheets.googleapis.com/v4/spreadsheets/${SHEET_ID}/values/${RANGE}?key=${API_KEY}`;
const response = await fetch(url);
if (!response.ok) {
throw new Error('Failed to fetch data');
}
const data = await response.json();
challenges = data.values.map(row => row[0]).filter(item => item !== "");
technologies = data.values.map(row => row[1]).filter(item => item !== "");
dataFetched = true;
}
async function generateRandom(type) {
const elementId = type;
const element = document.getElementById(elementId);
element.innerHTML = '<span class="loading">Loading...</span>';
try {
await fetchFromSheet();
const items = type === 'challenge' ? challenges : technologies;
const randomItem = items[Math.floor(Math.random() * items.length)];
element.innerText = `${type.charAt(0).toUpperCase() + type.slice(1)}: ${randomItem}`;
} catch (error) {
console.error('Error:', error);
element.innerHTML = '<span class="error">Failed to fetch data. Please try again.</span>';
}
}
async function generateSolution() {
const challengeText = document.getElementById('challenge').innerText.replace('Challenge: ', '');
const technologyText = document.getElementById('technology').innerText.replace('Technology: ', '');
const solutionElement = document.getElementById('solution');
if (!challengeText || !technologyText) {
solutionElement.innerHTML = '<span class="error">Please generate both a challenge and a technology first.</span>';
return;
}
solutionElement.innerHTML = '<span class="loading">Generating solution...</span>';
try {
const solution = await sendToLLM(challengeText, technologyText);
solutionElement.innerText = `Solution: ${solution}`;
} catch (error) {
console.error('Error:', error);
solutionElement.innerHTML = '<span class="error">Failed to generate solution. Please try again.</span>';
}
}
async function sendToLLM(challenge, technology) {
const payload = `Challenge: ${challenge}. Technology: ${technology}`;
console.log("Payload being sent to LLM:", payload); // Debugging
const response = await fetch(LLM_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Apikey': `Api-Key ${LLM_API_KEY}`
},
body: JSON.stringify({ payload })
});
if (!response.ok) {
throw new Error('Failed to generate solution');
}
const data = await response.json();
console.log("Response from LLM:", data); // Debugging
return data.text || "No solution generated.";
}
// JavaScript to Handle Footer Display
function dismissFooter() {
document.getElementById('extension-warning-footer').style.display = 'none';
localStorage.setItem('extensionWarningFooterDismissed', 'true');
}
window.onload = function() {
if (!localStorage.getItem('extensionWarningFooterDismissed')) {
document.getElementById('extension-warning-footer').style.display = 'block';
}
}
</script>
<!-- Footer Notification -->
<footer id="extension-warning-footer" style="display: none;">
You may experience issues with this site if certain browser extensions are enabled. <a href="#" style="color: #333; text-decoration: underline;" onclick="dismissFooter()">Learn more</a>
</footer>
</body>
</html>