Glitzee 47
Glitzee 47
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Health Assistant</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f0f4f7;
}
header {
background-color:#3951ff;
color: white;
padding: 20px;
text-align: center;
}
h1 {
margin: 0;
font-size: 4rem;
}
section {
margin: 20px;
padding: 20px;
background-color: white;
border-radius: 8px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
label {
font-weight: bold;
display: block;
margin-bottom: 10px;
}
textarea, input {
width: 100%;
padding: 10px;
margin-bottom: 15px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 1rem;
}
button {
background-color: #28a745;
color: white;
border: none;
padding: 10px 20px;
border-radius: 4px;
cursor: pointer;
font-size: 1rem;
}
button:hover {
background-color: #218838;
}
button:disabled {
background-color: #6c757d;
cursor: not-allowed;
}
footer {
text-align: center;
padding: 10px;
background-color: #333;
color: white;
}
#ai-recommendation {
font-size: 1.2rem;
margin-top: 20px;
padding: 20px;
border-radius: 8px;
background-color: #f8f9fa;
}
.emergency {
color: #dc3545;
background-color: #ffe6e6;
}
.urgent {
color: #fd7e14;
background-color: #fff3e6;
}
.moderate {
color: #ffc107;
background-color: #fff9e6;
}
.mild {
color: #28a745;
background-color: #e6ffe6;
}
.loading {
display: none;
text-align: center;
margin: 20px 0;
}
.loading:after {
content: '...';
animation: dots 1.5s steps(5, end) infinite;
}
@keyframes dots {
0%, 20% { content: '.'; }
40% { content: '..'; }
60% { content: '...'; }
80%, 100% { content: ''; }
}
.error {
color: #dc3545;
background-color: #ffe6e6;
padding: 10px;
border-radius: 4px;
margin: 10px 0;
}
.hidden {
display: none !important;
}
.front-page {
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: #3951ff;
color: white;
text-align: center;
}
.front-page h1 {
font-size: 2.5rem;
margin: 0;
}
.front-page p {
font-size: 1.2rem;
margin: 20px 0;
}
.front-page button {
background-color: #28a745;
color: white;
border: none;
padding: 12px 24px;
border-radius: 8px;
cursor: pointer;
font-size: 1rem;
}
.front-page button:hover {
background-color: #218838;
}
header {
background-color: #3951ff;
color: white;
padding: 15px;
text-align: center;
}
section {
margin: 20px;
padding: 20px;
background-color: white;
border-radius: 8px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
footer {
text-align: center;
padding: 10px;
background-color: #333;
color: white;
}
</style>
</head>
<body>
<section id="medical-history">
<h2>Your Medical History</h2>
<div id="inputError" style="'display:none'">
</div>
<form id="history-form">
</form>
</section>
<section id="current-symptoms">
<h2>Report Current Symptoms</h2>
<form id="symptom-form">
<label for="symptoms">Describe your current symptoms:</label>
<textarea id="symptoms" name="symptoms" required placeholder="e.g., severe
headache, fever, breathing issues"></textarea>
<section id="recommendation">
<h2>AI Recommended Action</h2>
<div id="ai-recommendation">
Once you submit your symptoms, the AI will provide a personalized recommendation
based on your medical history and current symptoms.
</div>
</section>
</div>
<script>
// Debugging Logs
console.log('Script Loaded.');
document.addEventListener('DOMContentLoaded', () => {
console.log('DOM Content Loaded.');
function transitionToApp() {
console.log('Button clicked. Transitioning...');
frontPage.classList.add('hidden'); // Hide the front page
mainApp.classList.remove('hidden'); // Show the main app
}
});
function saveMedicalHistory(){
try {
inputError.innerHTML='';
const medicalHistory = {
chronicConditions: document.getElementById('chronic-conditions').value.trim(),
currentMedication: document.getElementById('current-medication').value.trim(),
allergies: document.getElementById('allergies').value.trim(),
lifestyle: document.getElementById('lifestyle').value.trim()
};
localStorage.setItem('medicalHistory', JSON.stringify(medicalHistory));
} catch (error) {
const aiRecommendation = document.getElementById('ai-recommendation');
inputError.innerHTML = <div class="error"> <p>Error saving medical
history:error.message</p></div>;
}
}
/* NOT REQUIRED
let generatedText; // Declare the variable outside
generateText(prompt)
.then(text => {
generatedText = text; // Assign the value
alert(generatedText);
console.log('Generated Text:', generatedText);
})
.catch(error => {
console.error('Error:', error);
}); */
// Data for the request (the prompt you want the model to respond to)
const requestData = {
prompt: "Write a short story about a brave knight who saves a kingdom.",
maxOutputTokens: 100, // Maximum number of tokens (words) in the output (optional)
temperature: 0.7, // Controls creativity: 0.0 (conservative) to 1.0 (creative)
topP: 0.9 // Controls diversity of responses (optional)
};
if (!symptomsInput.value.trim() || !durationInput.value.trim()) {
aiRecommendation.innerHTML = <div class="error"><p>Please describe your symptoms and
specify their duration.</p></div>;
return;
}
loadingDiv.style.display = 'block';
const healthAI = '';//new EnhancedHealthAssistantAI();
try {
const currentSymptoms = {
symptoms: symptomsInput.value.trim(),
duration: durationInput.value.trim(),
triggers: document.getElementById('symptom-trigger').value.trim()
};
//healthAI.setMedicalHistory(medicalHistory);
//healthAI.setCurrentSymptoms(currentSymptoms);
</script>
<script>
function saveMedicalHistory2() {
try {
const medicalHistory = {
chronicConditions: document.getElementById('chronic-conditions').value.trim(),
currentMedication: document.getElementById('current-medication').value.trim(),
allergies: document.getElementById('allergies').value.trim(),
lifestyle: document.getElementById('lifestyle').value.trim()
};
localStorage.setItem('medicalHistory', JSON.stringify(medicalHistory));
if (!symptomsInput.value.trim() || !durationInput.value.trim()) {
aiRecommendation.innerHTML = `
<div class="error">
<p>Please describe your symptoms and specify their duration.</p>
</div>
`;
return;
}
loadingDiv.style.display = 'block';
const healthAI = new EnhancedHealthAssistantAI();
try {
const currentSymptoms = {
symptoms: symptomsInput.value.trim(),
duration: durationInput.value.trim(),
triggers: document.getElementById('symptom-trigger').value.trim()
};
healthAI.setMedicalHistory(medicalHistory);
healthAI.setCurrentSymptoms(currentSymptoms);
${recommendation.specificRecommendations.length > 0 ? `
<p><strong>Specific Recommendations:</strong></p>
<ul>${recommendation.specificRecommendations.map(rec =>
<li>${rec}</li>).join('')}</ul>
` : ''}
<div class="meta-analysis">
<p><strong>AI Analysis Insights:</strong></p>
<ul>
${recommendation.aiAnalysis.additionalInsights.map(insight =>
<li>${insight}</li>
).join('')}
</ul>
${recommendation.aiAnalysis.suggestedTests.length > 0 ? `
<p><strong>Suggested Medical Tests to Discuss with Your Doctor:</strong></p>
<ul>
${recommendation.aiAnalysis.suggestedTests.map(test =>
<li>${test}</li>
).join('')}
</ul>
` : ''}
<p class="disclaimer"><strong>Disclaimer:</strong><br>
${recommendation.disclaimer}</p>
</div>
`;
} catch (error) {
console.error("Error generating AI recommendation:", error);
aiRecommendation.innerHTML = `
<div class="error">
<p>There was an error generating the recommendation. Please try again later.</p>
<p>Error details: ${error.message}</p>
</div>
`;
} finally {
loadingDiv.style.display = 'none';
}
}
document.getElementById('history-form').addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
e.preventDefault();
saveMedicalHistory();
}
});
document.getElementById('symptom-form').addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
e.preventDefault();
getEnhancedRecommendation();
}
});
window.addEventListener('load', function() {
try {
const savedHistory = JSON.parse(localStorage.getItem('medicalHistory'));
if (savedHistory) {
document.getElementById('chronic-conditions').value = savedHistory.chronicConditions
|| '';
document.getElementById('current-medication').value = savedHistory.currentMedication
|| '';
document.getElementById('allergies').value = savedHistory.allergies || '';
document.getElementById('lifestyle').value = savedHistory.lifestyle || '';
}
} catch (error) {
console.error("Error loading saved medical history:", error);
}
});
</script>
</body>
</html>