371 lines
No EOL
17 KiB
PHP
371 lines
No EOL
17 KiB
PHP
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Enhanced Brief Processing...</title>
|
|
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;500;600;700&display=swap" rel="stylesheet">
|
|
<style>
|
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
body {
|
|
font-family: 'Montserrat', sans-serif;
|
|
background: #000000;
|
|
min-height: 100vh;
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: center;
|
|
padding: 20px;
|
|
}
|
|
.logo {
|
|
margin-bottom: 30px;
|
|
filter: invert(1);
|
|
}
|
|
.logo img {
|
|
height: 80px;
|
|
width: auto;
|
|
}
|
|
.container {
|
|
background: white;
|
|
padding: 40px;
|
|
border-radius: 20px;
|
|
box-shadow: 0 20px 40px rgba(255, 255, 255, 0.1);
|
|
max-width: 1000px;
|
|
width: 100%;
|
|
text-align: center;
|
|
}
|
|
h2 {
|
|
font-family: 'Montserrat', sans-serif;
|
|
font-weight: 600;
|
|
color: #333;
|
|
font-size: 28px;
|
|
margin-bottom: 20px;
|
|
}
|
|
.processing-status {
|
|
background: #f8f9fa;
|
|
padding: 20px;
|
|
border-radius: 10px;
|
|
margin-bottom: 20px;
|
|
border-left: 4px solid #007bff;
|
|
}
|
|
.processing-status h3 {
|
|
color: #007bff;
|
|
margin-bottom: 10px;
|
|
font-size: 18px;
|
|
}
|
|
.status-item {
|
|
display: flex;
|
|
align-items: center;
|
|
margin-bottom: 8px;
|
|
font-size: 14px;
|
|
}
|
|
.status-icon {
|
|
width: 20px;
|
|
height: 20px;
|
|
border-radius: 50%;
|
|
margin-right: 10px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
color: white;
|
|
font-weight: bold;
|
|
font-size: 12px;
|
|
}
|
|
.status-pending { background: #6c757d; }
|
|
.status-active { background: #007bff; animation: pulse 2s infinite; }
|
|
.status-complete { background: #28a745; }
|
|
.status-error { background: #dc3545; }
|
|
@keyframes pulse {
|
|
0% { opacity: 1; }
|
|
50% { opacity: 0.5; }
|
|
100% { opacity: 1; }
|
|
}
|
|
.streaming-log {
|
|
text-align: left;
|
|
background: #1e1e1e;
|
|
color: #d4d4d4;
|
|
border-radius: 10px;
|
|
padding: 20px;
|
|
max-height: 500px;
|
|
overflow-y: auto;
|
|
white-space: pre-wrap;
|
|
word-wrap: break-word;
|
|
font-family: 'Courier New', Courier, monospace;
|
|
font-size: 14px;
|
|
margin-bottom: 20px;
|
|
}
|
|
.results-summary {
|
|
background: #e8f5e8;
|
|
padding: 20px;
|
|
border-radius: 10px;
|
|
margin-bottom: 20px;
|
|
text-align: left;
|
|
border-left: 4px solid #28a745;
|
|
}
|
|
.results-summary h3 {
|
|
color: #28a745;
|
|
margin-bottom: 15px;
|
|
}
|
|
.summary-item {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
margin-bottom: 8px;
|
|
padding: 5px 0;
|
|
border-bottom: 1px solid #d4edda;
|
|
}
|
|
.summary-item:last-child {
|
|
border-bottom: none;
|
|
}
|
|
.download-section {
|
|
text-align: center;
|
|
margin-top: 30px;
|
|
}
|
|
.download-link {
|
|
display: inline-block;
|
|
text-decoration: none;
|
|
margin: 10px;
|
|
font-family: 'Montserrat', sans-serif;
|
|
font-weight: 600;
|
|
background: #000000;
|
|
color: white;
|
|
border: none;
|
|
padding: 15px 30px;
|
|
border-radius: 10px;
|
|
font-size: 16px;
|
|
transition: all 0.3s ease;
|
|
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
|
|
}
|
|
.download-link:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
|
|
background: #333333;
|
|
}
|
|
.back-link {
|
|
display: inline-block;
|
|
margin-top: 15px;
|
|
color: #333333;
|
|
text-decoration: none;
|
|
font-family: 'Montserrat', sans-serif;
|
|
font-size: 14px;
|
|
}
|
|
.back-link:hover {
|
|
color: #000000;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="logo">
|
|
<img src="Adidas_Logo.svg" alt="Adidas Logo">
|
|
</div>
|
|
<div class="container">
|
|
<h2>Enhanced Brief Processing</h2>
|
|
|
|
<div class="processing-status">
|
|
<h3>Multi-Pass Analysis Pipeline</h3>
|
|
<?php
|
|
$selected_model = isset($_POST['selected_model']) ? $_POST['selected_model'] : 'gemini-1.5-pro';
|
|
echo '<p style="margin-bottom: 15px; color: #28a745; font-weight: 500;">Using AI Model: ' . htmlspecialchars($selected_model) . '</p>';
|
|
?>
|
|
<div class="status-item">
|
|
<div class="status-icon status-active" id="stage1">1</div>
|
|
<span>Document Upload & Classification</span>
|
|
</div>
|
|
<div class="status-item">
|
|
<div class="status-icon status-pending" id="stage2">2</div>
|
|
<span>Document Structure Analysis</span>
|
|
</div>
|
|
<div class="status-item">
|
|
<div class="status-icon status-pending" id="stage3">3</div>
|
|
<span>Multi-Perspective Extraction</span>
|
|
</div>
|
|
<div class="status-item">
|
|
<div class="status-icon status-pending" id="stage4">4</div>
|
|
<span>Cross-Validation & Enhancement</span>
|
|
</div>
|
|
<div class="status-item">
|
|
<div class="status-icon status-pending" id="stage5">5</div>
|
|
<span>Final Output Generation</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="streaming-log">
|
|
<?php
|
|
function stream_and_capture_command($command, &$full_output) {
|
|
$handle = popen($command, 'r');
|
|
if ($handle === false) {
|
|
echo "Error: Failed to execute command.";
|
|
return false;
|
|
}
|
|
|
|
while (!feof($handle)) {
|
|
$line = fgets($handle);
|
|
if ($line !== false) {
|
|
$full_output .= $line;
|
|
echo htmlspecialchars($line) . "<br>";
|
|
|
|
// Update progress indicators based on log content
|
|
if (strpos($line, 'File uploaded:') !== false) {
|
|
echo '<script>document.getElementById("stage1").className = "status-icon status-complete"; document.getElementById("stage2").className = "status-icon status-active";</script>';
|
|
} elseif (strpos($line, 'Identified') !== false && strpos($line, 'sections') !== false) {
|
|
echo '<script>document.getElementById("stage2").className = "status-icon status-complete"; document.getElementById("stage3").className = "status-icon status-active";</script>';
|
|
} elseif (strpos($line, 'Multi-perspective analysis completed') !== false) {
|
|
echo '<script>document.getElementById("stage3").className = "status-icon status-complete"; document.getElementById("stage4").className = "status-icon status-active";</script>';
|
|
} elseif (strpos($line, 'Validation') !== false) {
|
|
echo '<script>document.getElementById("stage4").className = "status-icon status-complete"; document.getElementById("stage5").className = "status-icon status-active";</script>';
|
|
} elseif (strpos($line, 'Output File:') !== false) {
|
|
echo '<script>document.getElementById("stage5").className = "status-icon status-complete";</script>';
|
|
}
|
|
|
|
ob_flush();
|
|
flush();
|
|
}
|
|
}
|
|
|
|
$return_code = pclose($handle);
|
|
return $return_code === 0;
|
|
}
|
|
|
|
function parse_processing_summary($log_output) {
|
|
$summary = [];
|
|
$lines = explode("\n", $log_output);
|
|
|
|
foreach ($lines as $line) {
|
|
if (strpos($line, 'Document Type:') !== false) {
|
|
$summary['doc_type'] = trim(str_replace(['Document Type:', 'INFO', '-'], '', $line));
|
|
} elseif (strpos($line, 'Assets Extracted:') !== false) {
|
|
$summary['asset_count'] = trim(str_replace(['Assets Extracted:', 'INFO', '-'], '', $line));
|
|
} elseif (strpos($line, 'Confidence Score:') !== false) {
|
|
$summary['confidence'] = trim(str_replace(['Confidence Score:', 'INFO', '-'], '', $line));
|
|
} elseif (strpos($line, 'Processing Notes:') !== false) {
|
|
$summary['notes'] = trim(str_replace(['Processing Notes:', 'INFO', '-'], '', $line));
|
|
} elseif (strpos($line, '__COST_SUMMARY__:') !== false) {
|
|
$summary['total_cost'] = trim(str_replace('__COST_SUMMARY__:', '', $line));
|
|
} elseif (strpos($line, '__TOKEN_USAGE__:') !== false) {
|
|
$token_parts = explode(':', trim(str_replace('__TOKEN_USAGE__:', '', $line)));
|
|
if (count($token_parts) >= 3) {
|
|
$summary['input_tokens'] = $token_parts[0];
|
|
$summary['output_tokens'] = $token_parts[1];
|
|
$summary['total_tokens'] = $token_parts[2];
|
|
}
|
|
} elseif (strpos($line, 'Model Used:') !== false) {
|
|
$summary['model_used'] = trim(str_replace(['Model Used:', 'INFO', '-'], '', $line));
|
|
}
|
|
}
|
|
|
|
return $summary;
|
|
}
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_FILES["fileToUpload"])) {
|
|
$target_dir = "uploads/";
|
|
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
|
|
|
|
if (!is_dir($target_dir)) {
|
|
mkdir($target_dir, 0755, true);
|
|
}
|
|
|
|
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
|
|
$python_executable = '/Users/daveporter/Desktop/CODING-2024/ADIDAS-TEST-MULTIPASS/adi-gem-brief/bin/python';
|
|
$python_script = 'process_brief_enhanced.py';
|
|
|
|
// Use GPT-5 with high reasoning effort (hardcoded)
|
|
$selected_model = 'gpt-5';
|
|
|
|
$command = $python_executable . ' ' . $python_script . ' ' . escapeshellarg($target_file) . ' ' . escapeshellarg($selected_model) . ' 2>&1';
|
|
|
|
$full_log_output = '';
|
|
$success = stream_and_capture_command($command, $full_log_output);
|
|
|
|
// Parse processing summary
|
|
$summary = parse_processing_summary($full_log_output);
|
|
|
|
// Display results summary
|
|
if (!empty($summary)) {
|
|
echo '</div>'; // Close streaming log
|
|
echo '<div class="results-summary">';
|
|
echo '<h3>Processing Results Summary</h3>';
|
|
|
|
if (isset($summary['doc_type'])) {
|
|
echo '<div class="summary-item"><span><strong>Document Type:</strong></span><span>' . htmlspecialchars($summary['doc_type']) . '</span></div>';
|
|
}
|
|
if (isset($summary['asset_count'])) {
|
|
echo '<div class="summary-item"><span><strong>Assets Extracted:</strong></span><span>' . htmlspecialchars($summary['asset_count']) . '</span></div>';
|
|
}
|
|
if (isset($summary['confidence'])) {
|
|
echo '<div class="summary-item"><span><strong>Confidence Score:</strong></span><span>' . htmlspecialchars($summary['confidence']) . '</span></div>';
|
|
}
|
|
if (isset($summary['notes'])) {
|
|
echo '<div class="summary-item"><span><strong>Processing Notes:</strong></span><span>' . htmlspecialchars($summary['notes']) . '</span></div>';
|
|
}
|
|
|
|
echo '</div>'; // Close results summary
|
|
|
|
// Display cost information if available
|
|
if (isset($summary['total_cost']) || isset($summary['total_tokens'])) {
|
|
echo '<div class="cost-summary" style="background: #fff3cd; padding: 20px; border-radius: 10px; margin-bottom: 20px; border-left: 4px solid #ffc107;">';
|
|
echo '<h3 style="color: #856404; margin-bottom: 15px;">💰 Cost Analysis</h3>';
|
|
|
|
if (isset($summary['model_used'])) {
|
|
echo '<div class="summary-item"><span><strong>AI Model:</strong></span><span>' . htmlspecialchars($summary['model_used']) . '</span></div>';
|
|
}
|
|
if (isset($summary['total_cost'])) {
|
|
echo '<div class="summary-item"><span><strong>Total Cost:</strong></span><span style="color: #d9534f; font-weight: bold;">$' . htmlspecialchars($summary['total_cost']) . '</span></div>';
|
|
}
|
|
if (isset($summary['input_tokens'])) {
|
|
echo '<div class="summary-item"><span><strong>Input Tokens:</strong></span><span>' . number_format((int)$summary['input_tokens']) . '</span></div>';
|
|
}
|
|
if (isset($summary['output_tokens'])) {
|
|
echo '<div class="summary-item"><span><strong>Output Tokens:</strong></span><span>' . number_format((int)$summary['output_tokens']) . '</span></div>';
|
|
}
|
|
if (isset($summary['total_tokens'])) {
|
|
echo '<div class="summary-item"><span><strong>Total Tokens:</strong></span><span>' . number_format((int)$summary['total_tokens']) . '</span></div>';
|
|
}
|
|
|
|
echo '</div>'; // Close cost summary
|
|
}
|
|
|
|
echo '<div class="streaming-log" style="max-height: 200px;">'; // Reopen for filename
|
|
}
|
|
|
|
// Extract filename
|
|
$lines = explode("\n", trim($full_log_output));
|
|
$download_filename = '';
|
|
|
|
foreach ($lines as $line) {
|
|
if (strpos($line, '__FILENAME__:') !== false) {
|
|
$download_filename = trim(str_replace('__FILENAME__:', '', $line));
|
|
break;
|
|
}
|
|
}
|
|
|
|
if ($download_filename && file_exists($download_filename)) {
|
|
echo '</div>'; // Close streaming log
|
|
echo '<div class="download-section">';
|
|
echo '<a href="' . htmlspecialchars($download_filename) . '" class="download-link" download>';
|
|
echo 'Download Enhanced Extraction (' . htmlspecialchars(basename($download_filename)) . ')';
|
|
echo '</a>';
|
|
|
|
// Also provide link to original extraction for comparison
|
|
$original_filename = str_replace('-ENHANCED-EXTRACTION.csv', '-EXTRACTION.csv', $download_filename);
|
|
if (file_exists($original_filename)) {
|
|
echo '<a href="' . htmlspecialchars($original_filename) . '" class="download-link" download>';
|
|
echo 'Download Original Extraction (Compare)';
|
|
echo '</a>';
|
|
}
|
|
echo '</div>';
|
|
} else {
|
|
echo "<br><span style='color: #dc3545;'>Processing completed but output file not found. Please check the log above.</span>";
|
|
}
|
|
|
|
} else {
|
|
echo "<span style='color: #dc3545;'>Error: Could not move the uploaded file.</span>";
|
|
}
|
|
} else {
|
|
echo "<span style='color: #dc3545;'>No file uploaded or invalid request.</span>";
|
|
}
|
|
?>
|
|
</div>
|
|
|
|
<a href="index.php" class="back-link">Process Another File</a>
|
|
</div>
|
|
</body>
|
|
</html>
|