Enhanced Brief Processing
Multi-Pass Analysis Pipeline
Using AI Model: ' . htmlspecialchars($selected_model) . '';
?>
1
Document Upload & Classification
2
Document Structure Analysis
3
Multi-Perspective Extraction
4
Cross-Validation & Enhancement
5
Final Output Generation
";
// Update progress indicators based on log content
if (strpos($line, 'File uploaded:') !== false) {
echo '';
} elseif (strpos($line, 'Identified') !== false && strpos($line, 'sections') !== false) {
echo '';
} elseif (strpos($line, 'Multi-perspective analysis completed') !== false) {
echo '';
} elseif (strpos($line, 'Validation') !== false) {
echo '';
} elseif (strpos($line, 'Output File:') !== false) {
echo '';
}
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 '
'; // Close streaming log
echo '
';
echo '
Processing Results Summary
';
if (isset($summary['doc_type'])) {
echo '
Document Type:' . htmlspecialchars($summary['doc_type']) . '
';
}
if (isset($summary['asset_count'])) {
echo '
Assets Extracted:' . htmlspecialchars($summary['asset_count']) . '
';
}
if (isset($summary['confidence'])) {
echo '
Confidence Score:' . htmlspecialchars($summary['confidence']) . '
';
}
if (isset($summary['notes'])) {
echo '
Processing Notes:' . htmlspecialchars($summary['notes']) . '
';
}
echo '
'; // Close results summary
// Display cost information if available
if (isset($summary['total_cost']) || isset($summary['total_tokens'])) {
echo '
';
echo '
💰 Cost Analysis
';
if (isset($summary['model_used'])) {
echo '
AI Model:' . htmlspecialchars($summary['model_used']) . '
';
}
if (isset($summary['total_cost'])) {
echo '
Total Cost:$' . htmlspecialchars($summary['total_cost']) . '
';
}
if (isset($summary['input_tokens'])) {
echo '
Input Tokens:' . number_format((int)$summary['input_tokens']) . '
';
}
if (isset($summary['output_tokens'])) {
echo '
Output Tokens:' . number_format((int)$summary['output_tokens']) . '
';
}
if (isset($summary['total_tokens'])) {
echo '
Total Tokens:' . number_format((int)$summary['total_tokens']) . '
';
}
echo '
'; // Close cost summary
}
echo '
'; // 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 '
'; // Close streaming log
echo '
';
} else {
echo "
Processing completed but output file not found. Please check the log above.";
}
} else {
echo "
Error: Could not move the uploaded file.";
}
} else {
echo "
No file uploaded or invalid request.";
}
?>