|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>AI-Powered Web App</title>
|
|
<style>
|
|
:root {
|
|
--primary-color: #4A90E2;
|
|
--secondary-color: #f4f6f8;
|
|
--text-color: #333;
|
|
--btn-color: #4A90E2;
|
|
--btn-hover: #357ABD;
|
|
--card-bg: #fff;
|
|
--card-shadow: rgba(0, 0, 0, 0.1);
|
|
--border-radius: 8px;
|
|
--transition: 0.3s;
|
|
--max-width: 900px;
|
|
}
|
|
* {
|
|
box-sizing: border-box;
|
|
}
|
|
body {
|
|
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
|
color: var(--text-color);
|
|
background: var(--secondary-color);
|
|
margin: 0;
|
|
padding: 20px;
|
|
display: flex;
|
|
justify-content: center;
|
|
}
|
|
.container {
|
|
width: 100%;
|
|
max-width: var(--max-width);
|
|
}
|
|
h1 {
|
|
text-align: center;
|
|
color: var(--primary-color);
|
|
margin-bottom: 40px;
|
|
}
|
|
.section {
|
|
background: var(--card-bg);
|
|
padding: 20px;
|
|
margin-bottom: 30px;
|
|
border-radius: var(--border-radius);
|
|
box-shadow: 0 2px 8px var(--card-shadow);
|
|
transition: transform var(--transition);
|
|
}
|
|
.section:hover {
|
|
transform: translateY(-3px);
|
|
}
|
|
h2 {
|
|
margin-top: 0;
|
|
color: var(--primary-color);
|
|
border-bottom: 2px solid var(--secondary-color);
|
|
padding-bottom: 5px;
|
|
}
|
|
label {
|
|
display: block;
|
|
margin-top: 15px;
|
|
font-weight: bold;
|
|
}
|
|
input[type="file"], input[type="text"], button, textarea {
|
|
width: 100%;
|
|
padding: 10px;
|
|
margin-top: 8px;
|
|
border: 1px solid #ccc;
|
|
border-radius: var(--border-radius);
|
|
font-size: 1rem;
|
|
}
|
|
button {
|
|
background: var(--btn-color);
|
|
color: #fff;
|
|
border: none;
|
|
margin-top: 20px;
|
|
padding: 12px;
|
|
font-size: 1rem;
|
|
border-radius: var(--border-radius);
|
|
cursor: pointer;
|
|
transition: background var(--transition);
|
|
}
|
|
button:hover {
|
|
background: var(--btn-hover);
|
|
}
|
|
.results {
|
|
margin-top: 20px;
|
|
padding: 15px;
|
|
background: var(--secondary-color);
|
|
border-radius: var(--border-radius);
|
|
border: 1px solid #ddd;
|
|
min-height: 60px;
|
|
}
|
|
@media (min-width: 768px) {
|
|
.grid {
|
|
display: flex;
|
|
gap: 20px;
|
|
}
|
|
.grid > div {
|
|
flex: 1;
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>AI-Powered Web Application</h1>
|
|
|
|
|
|
<div class="grid">
|
|
|
|
<div class="section" id="analysis-section">
|
|
<h2>1. Document & Image Analysis</h2>
|
|
|
|
<label for="doc-input-summarize">Upload Document (PDF, DOCX, PPTX, XLSX):</label>
|
|
<input type="file" id="doc-input-summarize" accept=".pdf,.docx,.pptx,.xlsx" />
|
|
<button id="summarize-btn">Summarize Document</button>
|
|
<div class="results" id="summary-result">Your summary will appear here.</div>
|
|
|
|
|
|
<label for="img-input-caption">Upload Image (JPG, PNG):</label>
|
|
<input type="file" id="img-input-caption" accept="image/*" />
|
|
<button id="caption-btn">Generate Caption</button>
|
|
<div class="results" id="caption-result">Image caption will appear here.</div>
|
|
</div>
|
|
|
|
|
|
<div class="section" id="qa-section">
|
|
<h2>2. Intelligent Question Answering</h2>
|
|
<label for="file-input-qa">Upload Document or Image:</label>
|
|
<input type="file" id="file-input-qa" accept=".pdf,.docx,.pptx,.xlsx,image/*" />
|
|
<label for="question-input">Enter Your Question:</label>
|
|
<input type="text" id="question-input" placeholder="Type your question here..." />
|
|
<button id="qa-btn">Ask Question</button>
|
|
<div class="results" id="qa-result">Answer will appear here.</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
async function sendData(url, fileInput, extraData, resultContainer) {
|
|
const file = fileInput.files[0];
|
|
if (!file) {
|
|
resultContainer.textContent = 'Please select a file.';
|
|
return;
|
|
}
|
|
const formData = new FormData();
|
|
formData.append('file', file);
|
|
if (extraData) Object.keys(extraData).forEach(key => formData.append(key, extraData[key]));
|
|
resultContainer.textContent = 'Processing...';
|
|
try {
|
|
const res = await fetch(url, { method: 'POST', body: formData });
|
|
const data = await res.json();
|
|
resultContainer.textContent = data.result || JSON.stringify(data);
|
|
} catch (err) {
|
|
resultContainer.textContent = 'Error: ' + err.message;
|
|
}
|
|
}
|
|
document.getElementById('summarize-btn').addEventListener('click', () => {
|
|
sendData('/api/summarize', document.getElementById('doc-input-summarize'), null, document.getElementById('summary-result'));
|
|
});
|
|
document.getElementById('caption-btn').addEventListener('click', () => {
|
|
sendData('/api/caption', document.getElementById('img-input-caption'), null, document.getElementById('caption-result'));
|
|
});
|
|
document.getElementById('qa-btn').addEventListener('click', () => {
|
|
const q = document.getElementById('question-input').value.trim();
|
|
if (!q) { document.getElementById('qa-result').textContent = 'Please enter a question.'; return; }
|
|
sendData('/api/qa', document.getElementById('file-input-qa'), { question: q }, document.getElementById('qa-result'));
|
|
});
|
|
</script>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
|