Metafinder_AI / templates /index.html
schmidj's picture
Update templates/index.html
19148fb verified
Raw History Blame Contribute Delete
14.3 kB
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>MetaFinder - Metadata Extractor</title>
<style>
body {
font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
margin: 0;
background: linear-gradient(135deg, #1f4e79 0%, #2980b9 100%);
color: #111;
min-height: 100vh;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 40px 20px;
}
.header {
text-align: center;
margin-bottom: 40px;
}
h1 {
font-size: 32px;
margin: 0 0 8px;
color: #fff;
font-weight: 700;
}
p.hint {
color: #bdc3c7;
margin: 0;
font-size: 16px;
}
.upload-section {
display: grid;
grid-template-columns: 1fr auto 1fr;
gap: 30px;
margin-bottom: 40px;
align-items: center;
}
.or-divider {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
color: #fff;
font-weight: 600;
font-size: 16px;
}
.upload-card {
background: #fff;
border-radius: 16px;
padding: 40px;
text-align: center;
box-shadow: 0 8px 32px rgba(0,0,0,0.1);
border: 2px dashed transparent;
transition: all 0.3s ease;
position: relative;
}
.upload-card:hover {
border: 2px dashed transparent;
}
.upload-card.dragover {
border-color: #e74c3c;
background: #fdf2f2;
}
.pdf-icon {
width: 80px;
height: 80px;
background: #e74c3c;
border-radius: 12px;
margin: 0 auto 20px;
display: flex;
align-items: center;
justify-content: center;
position: relative;
}
.pdf-icon::before {
content: "PDF";
color: white;
font-weight: bold;
font-size: 14px;
position: absolute;
bottom: 8px;
right: 8px;
}
.pdf-icon::after {
content: "📄";
font-size: 32px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.upload-title {
font-size: 24px;
font-weight: 600;
color: #2c3e50;
margin: 0 0 12px;
}
.upload-instructions {
color: #7f8c8d;
margin: 0 0 24px;
font-size: 14px;
}
.upload-btn {
background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
color: white;
border: none;
padding: 12px 24px;
border-radius: 8px;
font-weight: 600;
font-size: 14px;
cursor: pointer;
transition: all 0.3s ease;
display: inline-flex;
align-items: center;
gap: 8px;
}
.upload-btn:hover {
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(231, 76, 60, 0.3);
}
.doi-card {
background: #fff;
border-radius: 16px;
padding: 40px;
box-shadow: 0 8px 32px rgba(0,0,0,0.1);
border: 1px solid #e1e8ed;
}
.doi-title {
font-size: 24px;
font-weight: 600;
color: #2c3e50;
margin: 0 0 12px;
}
.doi-instructions {
color: #7f8c8d;
margin: 0 0 24px;
font-size: 14px;
}
.doi-input {
width: 100%;
padding: 16px;
border: 2px solid #e1e8ed;
border-radius: 8px;
font-size: 16px;
transition: border-color 0.3s ease;
}
.doi-input:focus {
outline: none;
border-color: #3498db;
}
.actions {
display: flex;
gap: 12px;
justify-content: center;
margin-top: 30px;
}
button {
cursor: pointer;
border: 0;
padding: 14px 28px;
border-radius: 8px;
font-weight: 600;
font-size: 16px;
transition: all 0.3s ease;
}
.primary {
background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
color: #fff;
}
.primary:hover {
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(52, 152, 219, 0.3);
}
.secondary {
background: #ecf0f1;
color: #2c3e50;
}
.secondary:hover {
background: #d5dbdb;
}
.results-section {
background: #fff;
border-radius: 16px;
padding: 30px;
box-shadow: 0 8px 32px rgba(0,0,0,0.1);
margin-top: 30px;
}
.card {
border: 1px solid #e5e7eb;
border-radius: 10px;
padding: 16px;
background: #fafafa;
}
.kv {
display: grid;
grid-template-columns: 160px 1fr;
gap: 8px 12px;
}
.mono {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 13px;
}
.muted {
color: #6b7280;
}
.row-list {
display: grid;
gap: 6px;
}
.download {
margin-top: 12px;
}
.flash {
background: #fff7ed;
border: 1px solid #fed7aa;
padding: 10px 12px;
border-radius: 8px;
color: #9a3412;
margin-bottom: 12px;
}
.flash-warning {
background: #fef3c7;
border: 1px solid #f59e0b;
color: #92400e;
}
.flash-warning a {
color: #1d4ed8;
text-decoration: underline;
}
.flash-warning a:hover {
color: #1e40af;
}
.hidden {
display: none;
}
#pdf_file {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
cursor: pointer;
}
@media (max-width: 768px) {
.upload-section {
grid-template-columns: 1fr;
gap: 20px;
}
.or-divider {
order: 2;
margin: 10px 0;
}
.doi-card {
order: 3;
}
.container {
padding: 20px 10px;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>MetaFinder AI</h1>
<p class="hint">Upload a PDF or enter a DOI. Click Generate to see a summary.</p>
</div>
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
<div class="flash flash-{{ category }}">{{ message | safe }}</div>
{% endfor %}
{% endif %}
{% endwith %}
<form action="{{ url_for('process') }}" method="post" enctype="multipart/form-data" id="uploadForm">
<div class="upload-section">
<!-- PDF Upload Card -->
<div class="upload-card" id="uploadCard">
<div class="pdf-icon"></div>
<div class="upload-title">Upload PDF</div>
<div class="upload-instructions">Drag and drop a PDF here or click to browse</div>
<button type="button" class="upload-btn" onclick="document.getElementById('pdf_file').click()">
⬆️ Choose PDF File
</button>
<input id="pdf_file" name="pdf_file" type="file" accept="application/pdf" class="hidden">
</div>
<!-- OR Divider -->
<div class="or-divider">
OR
</div>
<!-- DOI Input Card -->
<div class="doi-card">
<div class="doi-title">Enter DOI</div>
<input id="doi" name="doi" type="text" class="doi-input" placeholder="10.xxxx/xxxxxx">
</div>
</div>
<!-- Custom Metadata Keys Section -->
<div style="margin-top: 20px; text-align: center;">
<div style="background: rgba(255,255,255,0.1); padding: 20px; border-radius: 12px; backdrop-filter: blur(10px); max-width: 600px; margin: 0 auto;">
<div style="color: #fff; font-weight: 600; margin-bottom: 12px; font-size: 16px;">Custom Data-Related Metadata Keys (Optional)</div>
<div style="color: #bdc3c7; font-size: 14px; margin-bottom: 16px;">Specify additional metadata keys you want to extract for data-related fields. Leave empty to use default keys.</div>
<input id="custom_keys" name="custom_keys" type="text"
placeholder="E.g., sampling_year, sampling_area, sampling_method, variables, species"
style="width: 100%; padding: 12px 16px; border: 2px solid rgba(255,255,255,0.3); border-radius: 8px; font-size: 14px; background: rgba(255,255,255,0.9); color: #333; box-sizing: border-box;">
</div>
</div>
<div class="actions">
<button class="primary" type="submit">Generate</button>
{% if metadata %}
<button class="secondary" type="button" id="downloadJson">Download JSON</button>
<a class="secondary" href="{{ url_for('index') }}" style="text-decoration:none; display:inline-block; padding:14px 28px; border-radius:8px;">Reset</a>
{% endif %}
</div>
</form>
{% if metadata %}
<div class="results-section">
<h2 style="margin:0 0 20px; font-size:24px; color:#2c3e50; font-weight:600;">Extracted Metadata</h2>
{% set study_keys = ['title','authors','publication_date','journal','doi','abstract','keywords','key_findings'] %}
<!-- Study-level metadata -->
<h3 style="margin:10px 0 12px; font-size:18px; color:#2c3e50; font-weight:600;">Study-level metadata</h3>
<div class="kv" style="margin-bottom:16px;">
{% for key, value in metadata.items() if key in study_keys %}
{% if value is not none and value != '' and value != [] and value != {} %}
<div class="muted">{{ key.replace('_', ' ').title() }}</div>
<div>
{% if value is mapping %}
<div class="mono">{{ value | tojson(indent=2) }}</div>
{% elif value is iterable and value is not string %}
{% if value | length > 0 %}
<div style="font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;">- {{ value | join('\n- ') | replace('\n', '<br>') | safe }}</div>
{% else %}
<div class="muted">None</div>
{% endif %}
{% else %}
{% if value is string and value | length > 100 %}
<div style="white-space:pre-wrap; max-height:120px; overflow:auto; font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;">{{ value }}</div>
{% else %}
<div style="font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;">{{ value }}</div>
{% endif %}
{% endif %}
</div>
{% endif %}
{% endfor %}
</div>
<!-- Data-level metadata -->
<h3 style="margin:16px 0 12px; font-size:18px; color:#2c3e50; font-weight:600;">Data-level metadata</h3>
<div class="kv">
{% for key, value in metadata.items() if key not in study_keys %}
{% if value is not none and value != '' and value != [] and value != {} %}
<div class="muted">{{ key.replace('_', ' ').title() }}</div>
<div>
{% if value is mapping %}
<div class="mono">{{ value | tojson(indent=2) }}</div>
{% elif value is iterable and value is not string %}
{% if value | length > 0 %}
<div style="font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;">- {{ value | join('\n- ') | replace('\n', '<br>') | safe }}</div>
{% else %}
<div class="muted">None</div>
{% endif %}
{% else %}
{% if value is string and value | length > 100 %}
<div style="white-space:pre-wrap; max-height:120px; overflow:auto; font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;">{{ value }}</div>
{% else %}
<div style="font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;">{{ value }}</div>
{% endif %}
{% endif %}
</div>
{% endif %}
{% endfor %}
</div>
<div class="download">
<h3 style="margin:20px 0 12px; font-size:16px; color:#6b7280; font-weight:600;">Raw JSON Data</h3>
<pre class="mono" id="jsonPreview" style="white-space:pre-wrap; background:#f8f9fa; border:1px solid #e5e7eb; border-radius:8px; padding:16px; max-height:300px; overflow:auto;">{{ metadata | tojson(indent=2) }}</pre>
</div>
</div>
{% endif %}
</div>
<script>
// Drag and drop functionality
const uploadCard = document.getElementById('uploadCard');
const fileInput = document.getElementById('pdf_file');
// Drag and drop events
uploadCard.addEventListener('dragover', (e) => {
e.preventDefault();
uploadCard.classList.add('dragover');
});
uploadCard.addEventListener('dragleave', () => {
uploadCard.classList.remove('dragover');
});
uploadCard.addEventListener('drop', (e) => {
e.preventDefault();
uploadCard.classList.remove('dragover');
const files = e.dataTransfer.files;
if (files.length > 0 && files[0].type === 'application/pdf') {
fileInput.files = files;
updateFileName(files[0].name);
}
});
// File input change
fileInput.addEventListener('change', (e) => {
if (e.target.files.length > 0) {
updateFileName(e.target.files[0].name);
}
});
function updateFileName(fileName) {
const instructions = uploadCard.querySelector('.upload-instructions');
instructions.textContent = `Selected: ${fileName}`;
instructions.style.color = '#27ae60';
instructions.style.fontWeight = '600';
}
// Download JSON functionality
{% if metadata %}
(function() {
const data = {{ metadata | tojson }};
const btn = document.getElementById('downloadJson');
if (btn) {
btn.addEventListener('click', function() {
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'metadata.json';
document.body.appendChild(a);
a.click();
a.remove();
URL.revokeObjectURL(url);
});
}
})();
{% endif %}
</script>
</body>
</html>