import { useState } from "react"; import { FileTextIcon, Loader2Icon } from "lucide-react"; import { ImageWithFallback } from "./ImageWithFallback"; import { ReportModal } from "./ReportModal"; import axios from "axios"; interface ResultsPanelProps { uploadedImage: string | null; result?: any; loading?: boolean; } export function ResultsPanel({ uploadedImage, result, loading }: ResultsPanelProps) { const [showReportModal, setShowReportModal] = useState(false); // Make loading detection robust: sometimes values arrive as the string "true" from deployed envs const isLoading = loading === true || String(loading) === "true"; // Helpful debug information when checking issues on deployed spaces (open browser devtools) // Keep as debug (console.debug) so it doesn't clutter normal logs. console.debug("ResultsPanel: props", { loading, isLoading, result }); const handleGenerateReport = async (formData: FormData) => { try { const baseURL = import.meta.env.MODE === "development" ? "http://127.0.0.1:7860" : window.location.origin; const response = await axios.post(`${baseURL}/reports/`, formData, { headers: { "Content-Type": "multipart/form-data" }, }); if (response.data.html_url) { // Open report in new tab window.open(`${baseURL}${response.data.html_url}`, "_blank"); } if (response.data.pdf_url) { // Open PDF in new tab when available window.open(`${baseURL}${response.data.pdf_url}`, "_blank"); } setShowReportModal(false); } catch (err: any) { console.error("Failed to generate report:", err); alert(err.response?.data?.error || "Failed to generate report"); } }; // Safely destructure result (keep undefined values when result is null) so we can render // a stable panel while loading and avoid early returns that change layout. const { model_used, detections, annotated_image_url, summary, // prediction (not used here) confidence, } = (result || {}) as any; return (
Automated Image Analysis
Analysing Image...
Abnormal Cells: {summary.abnormal_cells}
Normal Cells: {summary.normal_cells}
Average Confidence: {summary.avg_confidence?.toFixed(2)}%
{JSON.stringify(confidence, null, 2)}
)}