Spaces:
Running
Running
testing new gradio UI
Browse files- gradio_test.py +635 -139
gradio_test.py
CHANGED
@@ -536,11 +536,11 @@ class NeuroNestApp:
|
|
536 |
return stats
|
537 |
|
538 |
########################################
|
539 |
-
# GRADIO INTERFACE
|
540 |
########################################
|
541 |
|
542 |
def create_gradio_interface():
|
543 |
-
"""Create the Gradio interface"""
|
544 |
|
545 |
app = NeuroNestApp()
|
546 |
oneformer_ok, blackspot_ok = app.initialize()
|
@@ -557,7 +557,7 @@ def create_gradio_interface():
|
|
557 |
):
|
558 |
"""Wrapper function for Gradio interface"""
|
559 |
if image_path is None:
|
560 |
-
return None, None, None, "Please upload an image"
|
561 |
|
562 |
results = app.analyze_image(
|
563 |
image_path=image_path,
|
@@ -568,7 +568,7 @@ def create_gradio_interface():
|
|
568 |
)
|
569 |
|
570 |
if "error" in results:
|
571 |
-
return None, None, None, f"Error: {results['error']}"
|
572 |
|
573 |
seg_output = results['segmentation']['visualization'] if results['segmentation'] else None
|
574 |
blackspot_output = results['blackspot']['visualization'] if results['blackspot'] else None
|
@@ -595,158 +595,660 @@ def create_gradio_interface():
|
|
595 |
return seg_output, blackspot_output, contrast_output, report
|
596 |
|
597 |
def generate_comprehensive_report(results: Dict, contrast_report: str, blackspot_report: str) -> str:
|
598 |
-
"""Generate comprehensive analysis report"""
|
599 |
-
report = [
|
600 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
601 |
|
|
|
602 |
if results['segmentation']:
|
603 |
stats = results['statistics'].get('segmentation', {})
|
604 |
-
report.append("## π― Object
|
605 |
-
report.append(f"
|
606 |
-
|
|
|
|
|
|
|
|
|
|
|
607 |
report.append("")
|
608 |
|
609 |
-
|
610 |
-
report.append(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
611 |
report.append("")
|
612 |
|
|
|
613 |
report.append("## π¨ Universal Contrast Analysis")
|
614 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
615 |
report.append("")
|
616 |
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
|
|
621 |
if results['blackspot'] and results['statistics']['blackspot']['coverage_percentage'] > 0:
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
if
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
660 |
return "\n".join(report)
|
661 |
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
-
|
670 |
-
|
671 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
672 |
"""
|
673 |
|
674 |
-
with gr.Blocks() as interface:
|
675 |
-
|
676 |
-
gr.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
677 |
|
678 |
-
#
|
679 |
if not blackspot_ok:
|
680 |
-
gr.
|
681 |
-
|
682 |
-
|
|
|
|
|
683 |
""")
|
684 |
|
685 |
-
#
|
686 |
-
with gr.
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
711 |
|
712 |
-
#
|
713 |
-
with gr.
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
743 |
)
|
744 |
|
745 |
-
#
|
746 |
-
|
747 |
-
|
748 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
749 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
750 |
analyze_button.click(
|
751 |
fn=analyze_wrapper,
|
752 |
inputs=[
|
@@ -764,12 +1266,6 @@ def create_gradio_interface():
|
|
764 |
]
|
765 |
)
|
766 |
|
767 |
-
gr.Markdown("""
|
768 |
-
---
|
769 |
-
**NeuroNest** v2.0 - Enhanced with floor-only blackspot detection and universal contrast analysis
|
770 |
-
*Creating safer environments for cognitive health through AI*
|
771 |
-
""")
|
772 |
-
|
773 |
return interface
|
774 |
|
775 |
########################################
|
|
|
536 |
return stats
|
537 |
|
538 |
########################################
|
539 |
+
# ENHANCED GRADIO INTERFACE
|
540 |
########################################
|
541 |
|
542 |
def create_gradio_interface():
|
543 |
+
"""Create the enhanced Gradio interface with improved layout"""
|
544 |
|
545 |
app = NeuroNestApp()
|
546 |
oneformer_ok, blackspot_ok = app.initialize()
|
|
|
557 |
):
|
558 |
"""Wrapper function for Gradio interface"""
|
559 |
if image_path is None:
|
560 |
+
return None, None, None, "### β οΈ Please upload an image to begin analysis"
|
561 |
|
562 |
results = app.analyze_image(
|
563 |
image_path=image_path,
|
|
|
568 |
)
|
569 |
|
570 |
if "error" in results:
|
571 |
+
return None, None, None, f"### β Error: {results['error']}"
|
572 |
|
573 |
seg_output = results['segmentation']['visualization'] if results['segmentation'] else None
|
574 |
blackspot_output = results['blackspot']['visualization'] if results['blackspot'] else None
|
|
|
595 |
return seg_output, blackspot_output, contrast_output, report
|
596 |
|
597 |
def generate_comprehensive_report(results: Dict, contrast_report: str, blackspot_report: str) -> str:
|
598 |
+
"""Generate comprehensive analysis report with enhanced formatting"""
|
599 |
+
report = []
|
600 |
+
|
601 |
+
# Header with timestamp
|
602 |
+
report.append("# π§ NeuroNest Environmental Safety Analysis Report")
|
603 |
+
report.append(f"*Generated: {time.strftime('%Y-%m-%d %H:%M:%S')}*")
|
604 |
+
report.append("---\n")
|
605 |
+
|
606 |
+
# Quick Summary Box
|
607 |
+
report.append("## π Executive Summary")
|
608 |
+
|
609 |
+
# Determine overall safety status
|
610 |
+
has_critical = False
|
611 |
+
has_issues = False
|
612 |
+
|
613 |
+
if results['blackspot'] and results['statistics']['blackspot']['coverage_percentage'] > 0:
|
614 |
+
has_issues = True
|
615 |
+
if results['statistics']['blackspot']['coverage_percentage'] > 5:
|
616 |
+
has_critical = True
|
617 |
+
|
618 |
+
if results['contrast'] and results['statistics']['contrast']['critical_issues'] > 0:
|
619 |
+
has_critical = True
|
620 |
+
has_issues = True
|
621 |
+
elif results['contrast'] and results['statistics']['contrast']['low_contrast_pairs'] > 0:
|
622 |
+
has_issues = True
|
623 |
+
|
624 |
+
# Safety Status Box
|
625 |
+
if has_critical:
|
626 |
+
report.append("""
|
627 |
+
<div style='background-color: #fef2f2; border: 2px solid #dc2626; padding: 15px; border-radius: 8px; margin: 10px 0;'>
|
628 |
+
<h3 style='color: #dc2626; margin: 0;'>π¨ CRITICAL SAFETY ISSUES DETECTED</h3>
|
629 |
+
<p style='margin: 5px 0 0 0;'><em>Immediate modifications required for Alzheimer's/dementia care safety</em></p>
|
630 |
+
</div>
|
631 |
+
""")
|
632 |
+
elif has_issues:
|
633 |
+
report.append("""
|
634 |
+
<div style='background-color: #fffbeb; border: 2px solid #f59e0b; padding: 15px; border-radius: 8px; margin: 10px 0;'>
|
635 |
+
<h3 style='color: #f59e0b; margin: 0;'>β οΈ SAFETY CONCERNS IDENTIFIED</h3>
|
636 |
+
<p style='margin: 5px 0 0 0;'><em>Several areas need improvement for optimal cognitive accessibility</em></p>
|
637 |
+
</div>
|
638 |
+
""")
|
639 |
+
else:
|
640 |
+
report.append("""
|
641 |
+
<div style='background-color: #f0fdf4; border: 2px solid #22c55e; padding: 15px; border-radius: 8px; margin: 10px 0;'>
|
642 |
+
<h3 style='color: #22c55e; margin: 0;'>β
ENVIRONMENT PASSES SAFETY ASSESSMENT</h3>
|
643 |
+
<p style='margin: 5px 0 0 0;'><em>This space meets recommended standards for cognitive accessibility</em></p>
|
644 |
+
</div>
|
645 |
+
""")
|
646 |
+
|
647 |
+
report.append("\n---\n")
|
648 |
|
649 |
+
# Object Detection Results
|
650 |
if results['segmentation']:
|
651 |
stats = results['statistics'].get('segmentation', {})
|
652 |
+
report.append("## π― Object Detection Results")
|
653 |
+
report.append(f"""
|
654 |
+
<div style='background-color: #f3f4f6; padding: 15px; border-radius: 8px;'>
|
655 |
+
<strong>Total Objects Identified:</strong> {stats.get('num_classes', 'N/A')}<br>
|
656 |
+
<strong>Image Resolution:</strong> {stats.get('image_size', 'N/A')}<br>
|
657 |
+
<em style='color: #6b7280;'>Successfully identified floors, walls, furniture, and other room elements</em>
|
658 |
+
</div>
|
659 |
+
""")
|
660 |
report.append("")
|
661 |
|
662 |
+
# Blackspot Analysis Section
|
663 |
+
report.append("## β« Floor Blackspot Analysis")
|
664 |
+
if results['blackspot'] and results['statistics']['blackspot']['coverage_percentage'] > 0:
|
665 |
+
report.append("### π Detection Results:")
|
666 |
+
report.append(f"""
|
667 |
+
<div style='background-color: #1f2937; color: white; padding: 15px; border-radius: 8px; font-family: monospace;'>
|
668 |
+
{blackspot_report}
|
669 |
+
</div>
|
670 |
+
""")
|
671 |
+
|
672 |
+
# Severity assessment with visual indicators
|
673 |
+
coverage = results['statistics']['blackspot']['coverage_percentage']
|
674 |
+
if coverage > 10:
|
675 |
+
severity_color = "#dc2626"
|
676 |
+
severity_text = "SEVERE"
|
677 |
+
severity_desc = "Large dark areas detected - High fall risk"
|
678 |
+
severity_icon = "β"
|
679 |
+
elif coverage > 5:
|
680 |
+
severity_color = "#ef4444"
|
681 |
+
severity_text = "HIGH RISK"
|
682 |
+
severity_desc = "Significant dark areas present"
|
683 |
+
severity_icon = "π΄"
|
684 |
+
elif coverage > 2:
|
685 |
+
severity_color = "#f59e0b"
|
686 |
+
severity_text = "MODERATE"
|
687 |
+
severity_desc = "Some dark areas that may cause confusion"
|
688 |
+
severity_icon = "π‘"
|
689 |
+
else:
|
690 |
+
severity_color = "#22c55e"
|
691 |
+
severity_text = "LOW"
|
692 |
+
severity_desc = "Minor dark areas detected"
|
693 |
+
severity_icon = "π’"
|
694 |
+
|
695 |
+
report.append(f"""
|
696 |
+
<div style='background-color: {severity_color}22; border-left: 4px solid {severity_color}; padding: 10px; margin: 10px 0;'>
|
697 |
+
<strong style='color: {severity_color};'>{severity_icon} {severity_text}:</strong> {severity_desc}
|
698 |
+
</div>
|
699 |
+
""")
|
700 |
+
else:
|
701 |
+
report.append("""
|
702 |
+
<div style='background-color: #f0fdf4; padding: 15px; border-radius: 8px;'>
|
703 |
+
β
<strong>No hazardous blackspots detected on floor surfaces</strong>
|
704 |
+
</div>
|
705 |
+
""")
|
706 |
report.append("")
|
707 |
|
708 |
+
# Contrast Analysis Section
|
709 |
report.append("## π¨ Universal Contrast Analysis")
|
710 |
+
if results['contrast'] and results['statistics']['contrast']['low_contrast_pairs'] > 0:
|
711 |
+
cs = results['statistics']['contrast']
|
712 |
+
|
713 |
+
# Summary table with better styling
|
714 |
+
report.append("### π Analysis Summary:")
|
715 |
+
report.append("""
|
716 |
+
<table style='width: 100%; border-collapse: collapse; margin: 10px 0;'>
|
717 |
+
<thead style='background-color: #f3f4f6;'>
|
718 |
+
<tr>
|
719 |
+
<th style='padding: 10px; text-align: left; border-bottom: 2px solid #e5e7eb;'>Severity Level</th>
|
720 |
+
<th style='padding: 10px; text-align: center; border-bottom: 2px solid #e5e7eb;'>Count</th>
|
721 |
+
<th style='padding: 10px; text-align: left; border-bottom: 2px solid #e5e7eb;'>Impact</th>
|
722 |
+
</tr>
|
723 |
+
</thead>
|
724 |
+
<tbody>
|
725 |
+
""")
|
726 |
+
|
727 |
+
report.append(f"""
|
728 |
+
<tr style='background-color: #fef2f2;'>
|
729 |
+
<td style='padding: 10px; border-bottom: 1px solid #e5e7eb;'><strong>π΄ Critical</strong></td>
|
730 |
+
<td style='padding: 10px; text-align: center; border-bottom: 1px solid #e5e7eb;'><strong>{cs['critical_issues']}</strong></td>
|
731 |
+
<td style='padding: 10px; border-bottom: 1px solid #e5e7eb;'>Immediate safety hazard</td>
|
732 |
+
</tr>
|
733 |
+
<tr style='background-color: #fffbeb;'>
|
734 |
+
<td style='padding: 10px; border-bottom: 1px solid #e5e7eb;'><strong>π High</strong></td>
|
735 |
+
<td style='padding: 10px; text-align: center; border-bottom: 1px solid #e5e7eb;'><strong>{cs['high_priority_issues']}</strong></td>
|
736 |
+
<td style='padding: 10px; border-bottom: 1px solid #e5e7eb;'>Significant navigation risk</td>
|
737 |
+
</tr>
|
738 |
+
<tr style='background-color: #fefce8;'>
|
739 |
+
<td style='padding: 10px; border-bottom: 1px solid #e5e7eb;'><strong>π‘ Medium</strong></td>
|
740 |
+
<td style='padding: 10px; text-align: center; border-bottom: 1px solid #e5e7eb;'><strong>{cs['medium_priority_issues']}</strong></td>
|
741 |
+
<td style='padding: 10px; border-bottom: 1px solid #e5e7eb;'>Potential confusion</td>
|
742 |
+
</tr>
|
743 |
+
</tbody>
|
744 |
+
</table>
|
745 |
+
""")
|
746 |
+
|
747 |
+
# Detailed issues
|
748 |
+
report.append("### π Detailed Findings:")
|
749 |
+
report.append("""
|
750 |
+
<div style='background-color: #f9fafb; border: 1px solid #e5e7eb; padding: 15px; border-radius: 8px; font-family: monospace; font-size: 0.9em;'>
|
751 |
+
<pre style='margin: 0; white-space: pre-wrap;'>""" + contrast_report + """</pre>
|
752 |
+
</div>
|
753 |
+
""")
|
754 |
+
else:
|
755 |
+
report.append("""
|
756 |
+
<div style='background-color: #f0fdf4; padding: 15px; border-radius: 8px;'>
|
757 |
+
β
<strong>All adjacent objects have sufficient contrast</strong><br>
|
758 |
+
<em style='color: #6b7280;'>Environment meets WCAG 2.1 accessibility guidelines</em>
|
759 |
+
</div>
|
760 |
+
""")
|
761 |
report.append("")
|
762 |
|
763 |
+
# Recommendations Section
|
764 |
+
report.append("## π‘ Actionable Recommendations")
|
765 |
+
|
766 |
+
recommendations = []
|
767 |
+
|
768 |
if results['blackspot'] and results['statistics']['blackspot']['coverage_percentage'] > 0:
|
769 |
+
recommendations.append({
|
770 |
+
'priority': 'HIGH',
|
771 |
+
'category': 'Blackspot Mitigation',
|
772 |
+
'icon': 'π‘',
|
773 |
+
'actions': [
|
774 |
+
"Install brighter LED lighting (3000+ lumens) in affected areas",
|
775 |
+
"Replace dark flooring with light-colored alternatives (beige, light gray)",
|
776 |
+
"Add light-colored area rugs or runners over dark spots",
|
777 |
+
"Install motion-activated pathway lighting at floor level"
|
778 |
+
]
|
779 |
+
})
|
780 |
+
|
781 |
+
if results['contrast']:
|
782 |
+
critical_count = results['statistics']['contrast']['critical_issues']
|
783 |
+
high_count = results['statistics']['contrast']['high_priority_issues']
|
784 |
+
|
785 |
+
if critical_count > 0:
|
786 |
+
recommendations.append({
|
787 |
+
'priority': 'CRITICAL',
|
788 |
+
'category': 'Critical Contrast Improvements',
|
789 |
+
'icon': 'π¨',
|
790 |
+
'actions': [
|
791 |
+
"Paint doors in colors that contrast strongly with walls (e.g., dark blue doors on light walls)",
|
792 |
+
"Add high-contrast tape or strips to stair edges",
|
793 |
+
"Install contrasting baseboards between floors and walls",
|
794 |
+
"Use furniture colors that contrast with both floor and wall colors"
|
795 |
+
]
|
796 |
+
})
|
797 |
+
|
798 |
+
if high_count > 0:
|
799 |
+
recommendations.append({
|
800 |
+
'priority': 'HIGH',
|
801 |
+
'category': 'High Priority Contrast Fixes',
|
802 |
+
'icon': 'β οΈ',
|
803 |
+
'actions': [
|
804 |
+
"Replace similar-colored furniture with contrasting alternatives",
|
805 |
+
"Add colorful cushions or throws to distinguish seating",
|
806 |
+
"Install LED strip lighting under furniture edges",
|
807 |
+
"Use contrasting placemats and table runners"
|
808 |
+
]
|
809 |
+
})
|
810 |
+
|
811 |
+
if recommendations:
|
812 |
+
# Sort by priority
|
813 |
+
priority_order = {'CRITICAL': 0, 'HIGH': 1, 'MEDIUM': 2}
|
814 |
+
recommendations.sort(key=lambda x: priority_order.get(x['priority'], 3))
|
815 |
+
|
816 |
+
for rec in recommendations:
|
817 |
+
if rec['priority'] == 'CRITICAL':
|
818 |
+
bg_color = "#fef2f2"
|
819 |
+
border_color = "#dc2626"
|
820 |
+
timeline = "IMMEDIATE ACTION REQUIRED"
|
821 |
+
elif rec['priority'] == 'HIGH':
|
822 |
+
bg_color = "#fffbeb"
|
823 |
+
border_color = "#f59e0b"
|
824 |
+
timeline = "Address Within 1 Week"
|
825 |
+
else:
|
826 |
+
bg_color = "#f0f9ff"
|
827 |
+
border_color = "#3b82f6"
|
828 |
+
timeline = "Address Within 1 Month"
|
829 |
+
|
830 |
+
report.append(f"""
|
831 |
+
<div style='background-color: {bg_color}; border-left: 4px solid {border_color}; padding: 15px; margin: 15px 0; border-radius: 4px;'>
|
832 |
+
<h3 style='margin: 0 0 10px 0; color: {border_color};'>{rec['icon']} {rec['category']}</h3>
|
833 |
+
<p style='margin: 0 0 10px 0; font-style: italic; color: #6b7280;'>{timeline}</p>
|
834 |
+
<ul style='margin: 0; padding-left: 20px;'>
|
835 |
+
""")
|
836 |
+
|
837 |
+
for action in rec['actions']:
|
838 |
+
report.append(f"<li style='margin: 5px 0;'>{action}</li>")
|
839 |
+
|
840 |
+
report.append("""
|
841 |
+
</ul>
|
842 |
+
</div>
|
843 |
+
""")
|
844 |
+
else:
|
845 |
+
report.append("""
|
846 |
+
<div style='background-color: #f0fdf4; padding: 20px; border-radius: 8px; text-align: center;'>
|
847 |
+
<h3 style='color: #22c55e; margin: 0;'>β
No immediate actions required</h3>
|
848 |
+
<p style='margin: 10px 0 0 0;'>This environment is well-optimized for individuals with Alzheimer's or dementia.</p>
|
849 |
+
</div>
|
850 |
+
""")
|
851 |
+
|
852 |
+
# Footer
|
853 |
+
report.append("""
|
854 |
+
---
|
855 |
+
<div style='text-align: center; color: #6b7280; margin-top: 30px; font-size: 0.9em;'>
|
856 |
+
<em>Report generated by NeuroNest v2.0 - Texas State University</em>
|
857 |
+
</div>
|
858 |
+
""")
|
859 |
+
|
860 |
return "\n".join(report)
|
861 |
|
862 |
+
# Custom CSS for enhanced styling
|
863 |
+
css = """
|
864 |
+
.gradio-container {
|
865 |
+
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
866 |
+
max-width: 1400px !important;
|
867 |
+
margin: 0 auto;
|
868 |
+
}
|
869 |
+
.main-header {
|
870 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
871 |
+
color: white;
|
872 |
+
padding: 2rem;
|
873 |
+
border-radius: 12px;
|
874 |
+
margin-bottom: 2rem;
|
875 |
+
text-align: center;
|
876 |
+
}
|
877 |
+
.main-header h1 {
|
878 |
+
margin: 0 0 0.5rem 0;
|
879 |
+
font-size: 2.5rem;
|
880 |
+
font-weight: 700;
|
881 |
+
}
|
882 |
+
.main-header p {
|
883 |
+
margin: 0;
|
884 |
+
opacity: 0.9;
|
885 |
+
font-size: 1.1rem;
|
886 |
+
}
|
887 |
+
.control-panel {
|
888 |
+
background-color: #f9fafb;
|
889 |
+
border: 1px solid #e5e7eb;
|
890 |
+
border-radius: 12px;
|
891 |
+
padding: 1.5rem;
|
892 |
+
margin-bottom: 1.5rem;
|
893 |
+
}
|
894 |
+
.info-box {
|
895 |
+
background-color: #eff6ff;
|
896 |
+
border: 1px solid #3b82f6;
|
897 |
+
border-radius: 8px;
|
898 |
+
padding: 1rem;
|
899 |
+
margin: 1rem 0;
|
900 |
+
}
|
901 |
+
.warning-box {
|
902 |
+
background-color: #fef3c7;
|
903 |
+
border: 1px solid #f59e0b;
|
904 |
+
border-radius: 8px;
|
905 |
+
padding: 1rem;
|
906 |
+
margin: 1rem 0;
|
907 |
+
}
|
908 |
+
.button-primary {
|
909 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
|
910 |
+
color: white !important;
|
911 |
+
font-size: 1.2rem !important;
|
912 |
+
font-weight: 600 !important;
|
913 |
+
padding: 14px 28px !important;
|
914 |
+
border-radius: 8px !important;
|
915 |
+
border: none !important;
|
916 |
+
cursor: pointer !important;
|
917 |
+
transition: transform 0.2s !important;
|
918 |
+
}
|
919 |
+
.button-primary:hover {
|
920 |
+
transform: translateY(-2px) !important;
|
921 |
+
box-shadow: 0 10px 20px rgba(0,0,0,0.1) !important;
|
922 |
+
}
|
923 |
+
.result-section {
|
924 |
+
margin-top: 2rem;
|
925 |
+
}
|
926 |
+
.markdown-text {
|
927 |
+
font-size: 1.05rem;
|
928 |
+
line-height: 1.7;
|
929 |
+
color: #1f2937;
|
930 |
+
}
|
931 |
+
.analysis-report {
|
932 |
+
background-color: #ffffff;
|
933 |
+
border: 1px solid #e5e7eb;
|
934 |
+
border-radius: 12px;
|
935 |
+
padding: 2rem;
|
936 |
+
margin-top: 1.5rem;
|
937 |
+
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
938 |
+
}
|
939 |
"""
|
940 |
|
941 |
+
with gr.Blocks(css=css, title="NeuroNest - Environmental Safety Analysis", theme=gr.themes.Soft()) as interface:
|
942 |
+
# Enhanced Header
|
943 |
+
gr.HTML("""
|
944 |
+
<div class="main-header">
|
945 |
+
<h1>π§ NeuroNest: AI-Powered Environment Safety Analysis</h1>
|
946 |
+
<p>Advanced visual analysis for Alzheimer's and dementia care environments</p>
|
947 |
+
<p style="font-size: 0.9rem; margin-top: 0.5rem;">Texas State CS & Interior Design Dept. β’ Abheek Pradhan, Dr. Nadim Adi, Dr. Greg Lakomski</p>
|
948 |
+
</div>
|
949 |
+
""")
|
950 |
+
|
951 |
+
# Quick Start Guide
|
952 |
+
with gr.Row():
|
953 |
+
gr.HTML("""
|
954 |
+
<div class="info-box" style="width: 100%;">
|
955 |
+
<h3 style="margin-top: 0;">π Quick Start Guide</h3>
|
956 |
+
<ol style="margin: 10px 0;">
|
957 |
+
<li><strong>Upload</strong> a well-lit photo of the room</li>
|
958 |
+
<li><strong>Adjust</strong> detection settings if needed (optional)</li>
|
959 |
+
<li><strong>Click</strong> "Analyze Environment" button</li>
|
960 |
+
<li><strong>Review</strong> the visual results and detailed report below</li>
|
961 |
+
</ol>
|
962 |
+
<p style="margin-bottom: 0;"><em>The analysis identifies safety hazards and provides actionable recommendations for creating dementia-friendly spaces.</em></p>
|
963 |
+
</div>
|
964 |
+
""")
|
965 |
|
966 |
+
# System status notification
|
967 |
if not blackspot_ok:
|
968 |
+
gr.HTML("""
|
969 |
+
<div class="warning-box">
|
970 |
+
<strong>β οΈ Limited Functionality:</strong> Blackspot detection model not available.
|
971 |
+
Upload the model to HuggingFace or place in local directory to enable floor hazard detection.
|
972 |
+
</div>
|
973 |
""")
|
974 |
|
975 |
+
# Analysis Controls Section
|
976 |
+
with gr.Group():
|
977 |
+
gr.Markdown("## ποΈ Analysis Settings")
|
978 |
+
|
979 |
+
with gr.Row():
|
980 |
+
with gr.Column(scale=1):
|
981 |
+
gr.HTML("""
|
982 |
+
<div class="control-panel">
|
983 |
+
<h4 style="margin-top: 0;">π Detection Options</h4>
|
984 |
+
""")
|
985 |
+
|
986 |
+
enable_blackspot = gr.Checkbox(
|
987 |
+
value=blackspot_ok,
|
988 |
+
label="Enable Floor Blackspot Detection",
|
989 |
+
info="Identifies dark areas on floors that may appear as holes to people with dementia",
|
990 |
+
interactive=blackspot_ok,
|
991 |
+
elem_classes="checkbox-custom"
|
992 |
+
)
|
993 |
+
|
994 |
+
blackspot_threshold = gr.Slider(
|
995 |
+
minimum=0.1,
|
996 |
+
maximum=0.9,
|
997 |
+
value=0.5,
|
998 |
+
step=0.05,
|
999 |
+
label="Detection Sensitivity",
|
1000 |
+
info="Lower values detect lighter shadows β’ Higher values detect only very dark areas",
|
1001 |
+
visible=blackspot_ok,
|
1002 |
+
elem_classes="slider-custom"
|
1003 |
+
)
|
1004 |
+
|
1005 |
+
gr.HTML("</div>")
|
1006 |
+
|
1007 |
+
with gr.Column(scale=1):
|
1008 |
+
gr.HTML("""
|
1009 |
+
<div class="control-panel">
|
1010 |
+
<h4 style="margin-top: 0;">π¨ Contrast Analysis</h4>
|
1011 |
+
""")
|
1012 |
+
|
1013 |
+
enable_contrast = gr.Checkbox(
|
1014 |
+
value=True,
|
1015 |
+
label="Enable Universal Contrast Analysis",
|
1016 |
+
info="Evaluates visibility between all adjacent objects (walls, floors, furniture)",
|
1017 |
+
elem_classes="checkbox-custom"
|
1018 |
+
)
|
1019 |
+
|
1020 |
+
contrast_threshold = gr.Slider(
|
1021 |
+
minimum=3.0,
|
1022 |
+
maximum=7.0,
|
1023 |
+
value=4.5,
|
1024 |
+
step=0.1,
|
1025 |
+
label="WCAG Contrast Threshold",
|
1026 |
+
info="4.5:1 = Standard accessibility β’ 7:1 = Enhanced for critical areas",
|
1027 |
+
elem_classes="slider-custom"
|
1028 |
+
)
|
1029 |
+
|
1030 |
+
gr.HTML("</div>")
|
1031 |
|
1032 |
+
# Image Upload Section
|
1033 |
+
with gr.Group():
|
1034 |
+
gr.Markdown("## πΈ Room Image Upload")
|
1035 |
+
|
1036 |
+
with gr.Row():
|
1037 |
+
with gr.Column(scale=2):
|
1038 |
+
image_input = gr.Image(
|
1039 |
+
label="Upload Room Photo",
|
1040 |
+
type="filepath",
|
1041 |
+
height=400,
|
1042 |
+
elem_classes="image-upload"
|
1043 |
+
)
|
1044 |
+
|
1045 |
+
analyze_button = gr.Button(
|
1046 |
+
"π Analyze Environment",
|
1047 |
+
variant="primary",
|
1048 |
+
size="lg",
|
1049 |
+
elem_classes="button-primary"
|
1050 |
+
)
|
1051 |
+
|
1052 |
+
with gr.Column(scale=1):
|
1053 |
+
gr.HTML("""
|
1054 |
+
<div class="info-box">
|
1055 |
+
<h4 style="margin-top: 0;">π· Photo Guidelines</h4>
|
1056 |
+
<ul style="margin: 10px 0;">
|
1057 |
+
<li>Stand in corner for wide view</li>
|
1058 |
+
<li>Include floor, walls & furniture</li>
|
1059 |
+
<li>Turn on all room lights</li>
|
1060 |
+
<li>Avoid shadows and glare</li>
|
1061 |
+
<li>Use horizontal orientation</li>
|
1062 |
+
</ul>
|
1063 |
+
<p style="margin-bottom: 0;"><strong>Best:</strong> Daytime photos with natural light</p>
|
1064 |
+
</div>
|
1065 |
+
""")
|
1066 |
+
|
1067 |
+
# Results Section
|
1068 |
+
with gr.Group():
|
1069 |
+
gr.Markdown("## π¬ Visual Analysis Results")
|
1070 |
+
|
1071 |
+
gr.HTML("""
|
1072 |
+
<p style="color: #6b7280; margin-bottom: 1rem;">
|
1073 |
+
Hover over images for details β’ Colors indicate: π’ Safe β’ π‘ Caution β’ π΄ Hazard
|
1074 |
+
</p>
|
1075 |
+
""")
|
1076 |
+
|
1077 |
+
with gr.Row():
|
1078 |
+
with gr.Column():
|
1079 |
+
seg_display = gr.Image(
|
1080 |
+
label="π― Object Segmentation",
|
1081 |
+
height=300,
|
1082 |
+
interactive=False,
|
1083 |
+
elem_classes="result-image"
|
1084 |
+
)
|
1085 |
+
gr.HTML("""
|
1086 |
+
<p style="text-align: center; color: #6b7280; font-size: 0.9rem; margin-top: 0.5rem;">
|
1087 |
+
Identifies all room elements
|
1088 |
+
</p>
|
1089 |
+
""")
|
1090 |
+
|
1091 |
+
with gr.Column():
|
1092 |
+
blackspot_display = gr.Image(
|
1093 |
+
label="β« Floor Blackspot Detection",
|
1094 |
+
height=300,
|
1095 |
+
interactive=False,
|
1096 |
+
visible=blackspot_ok,
|
1097 |
+
elem_classes="result-image"
|
1098 |
+
)
|
1099 |
+
if blackspot_ok:
|
1100 |
+
gr.HTML("""
|
1101 |
+
<p style="text-align: center; color: #6b7280; font-size: 0.9rem; margin-top: 0.5rem;">
|
1102 |
+
Red = Hazardous dark areas
|
1103 |
+
</p>
|
1104 |
+
""")
|
1105 |
+
|
1106 |
+
with gr.Column():
|
1107 |
+
contrast_display = gr.Image(
|
1108 |
+
label="π¨ Contrast Analysis",
|
1109 |
+
height=300,
|
1110 |
+
interactive=False,
|
1111 |
+
elem_classes="result-image"
|
1112 |
+
)
|
1113 |
+
gr.HTML("""
|
1114 |
+
<p style="text-align: center; color: #6b7280; font-size: 0.9rem; margin-top: 0.5rem;">
|
1115 |
+
Colored borders = Low contrast
|
1116 |
+
</p>
|
1117 |
+
""")
|
1118 |
+
|
1119 |
+
# Detailed Report Section
|
1120 |
+
with gr.Group():
|
1121 |
+
gr.Markdown("## π Comprehensive Safety Report")
|
1122 |
+
|
1123 |
+
analysis_report = gr.Markdown(
|
1124 |
+
value="""
|
1125 |
+
<div style='text-align: center; padding: 3rem; color: #6b7280;'>
|
1126 |
+
<p style='font-size: 1.2rem;'>π€ Upload an image and click 'Analyze Environment' to generate your safety report</p>
|
1127 |
+
<p>The report will include detailed findings and personalized recommendations</p>
|
1128 |
+
</div>
|
1129 |
+
""",
|
1130 |
+
elem_classes="analysis-report markdown-text"
|
1131 |
)
|
1132 |
|
1133 |
+
# Detailed Guide (Collapsible)
|
1134 |
+
with gr.Accordion("π Detailed User Guide & Best Practices", open=False):
|
1135 |
+
gr.Markdown("""
|
1136 |
+
## π― Understanding the Analysis
|
1137 |
+
|
1138 |
+
### What Each Analysis Does:
|
1139 |
+
|
1140 |
+
**1. Object Segmentation** π―
|
1141 |
+
- Identifies all elements in the room (floors, walls, furniture, etc.)
|
1142 |
+
- Creates a foundation map for other analyses
|
1143 |
+
- Helps understand spatial relationships
|
1144 |
+
|
1145 |
+
**2. Floor Blackspot Detection** β«
|
1146 |
+
- Finds dark areas on walking surfaces only
|
1147 |
+
- Ignores shadows on walls or furniture
|
1148 |
+
- Critical for preventing falls in dementia patients
|
1149 |
+
|
1150 |
+
**3. Universal Contrast Analysis** π¨
|
1151 |
+
- Examines color differences between ALL adjacent objects
|
1152 |
+
- Not just floor-to-furniture, but everything touching
|
1153 |
+
- Ensures clear visual boundaries throughout the space
|
1154 |
+
|
1155 |
+
### π Interpreting Results:
|
1156 |
+
|
1157 |
+
**Severity Levels:**
|
1158 |
+
- **π΄ Critical**: Immediate safety hazard - fix within 24 hours
|
1159 |
+
- **π High**: Significant risk - address within 1 week
|
1160 |
+
- **π‘ Medium**: Potential confusion - fix within 1 month
|
1161 |
+
- **π’ Low/Safe**: Acceptable for most individuals
|
1162 |
+
|
1163 |
+
**WCAG Contrast Ratios:**
|
1164 |
+
- **3:1** - Minimum for large text/graphics
|
1165 |
+
- **4.5:1** - Standard for normal text (recommended)
|
1166 |
+
- **7:1** - Enhanced for critical areas like stairs
|
1167 |
+
|
1168 |
+
### π‘ Common Issues & Solutions:
|
1169 |
+
|
1170 |
+
**Low Contrast Problems:**
|
1171 |
+
- White walls + beige furniture β Add colorful cushions
|
1172 |
+
- Similar floor/wall colors β Install contrasting baseboards
|
1173 |
+
- Invisible door frames β Paint doors in contrasting colors
|
1174 |
+
|
1175 |
+
**Blackspot Hazards:**
|
1176 |
+
- Dark rugs on light floors β Replace with light colors
|
1177 |
+
- Shadows from poor lighting β Add floor-level LED strips
|
1178 |
+
- Dark flooring materials β Install light-colored overlays
|
1179 |
+
|
1180 |
+
### π Room-Specific Tips:
|
1181 |
+
|
1182 |
+
**Living Room:**
|
1183 |
+
- Ensure sofa contrasts with floor AND wall
|
1184 |
+
- Coffee tables need defined edges
|
1185 |
+
- Pathways should be clearly visible
|
1186 |
+
|
1187 |
+
**Bedroom:**
|
1188 |
+
- Bed frame must contrast with floor
|
1189 |
+
- Night path to bathroom needs good visibility
|
1190 |
+
- Nightstands should stand out from walls
|
1191 |
+
|
1192 |
+
**Bathroom:**
|
1193 |
+
- Critical contrast between floor and fixtures
|
1194 |
+
- Non-slip surfaces in contrasting colors
|
1195 |
+
- Grab bars in colors that pop against walls
|
1196 |
+
|
1197 |
+
### πΈ Taking Better Photos:
|
1198 |
+
|
1199 |
+
1. **Lighting**: Turn on ALL lights, open curtains
|
1200 |
+
2. **Angle**: Stand in corner, capture whole room
|
1201 |
+
3. **Height**: Hold camera at eye level
|
1202 |
+
4. **Multiple**: Take several angles if needed
|
1203 |
+
5. **Quality**: Higher resolution = better analysis
|
1204 |
+
|
1205 |
+
### β οΈ Special Considerations:
|
1206 |
+
|
1207 |
+
- Patterns can be confusing - solid colors work better
|
1208 |
+
- Glossy surfaces may create false shadows
|
1209 |
+
- Consider time of day - shadows change
|
1210 |
+
- Test changes with actual lighting conditions
|
1211 |
+
""")
|
1212 |
|
1213 |
+
# Resource Links
|
1214 |
+
with gr.Row():
|
1215 |
+
gr.HTML("""
|
1216 |
+
<div style='background-color: #f3f4f6; padding: 20px; border-radius: 12px; margin-top: 2rem;'>
|
1217 |
+
<h4 style='margin-top: 0;'>π Additional Resources</h4>
|
1218 |
+
<div style='display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 15px;'>
|
1219 |
+
<div>
|
1220 |
+
<strong>π WCAG Guidelines</strong><br>
|
1221 |
+
<a href='https://www.w3.org/WAI/WCAG21/quickref/' target='_blank'>Web Accessibility Standards</a>
|
1222 |
+
</div>
|
1223 |
+
<div>
|
1224 |
+
<strong>π Dementia Design</strong><br>
|
1225 |
+
<a href='https://www.alzheimers.org.uk/get-support/making-your-home-dementia-friendly' target='_blank'>Home Modification Guide</a>
|
1226 |
+
</div>
|
1227 |
+
<div>
|
1228 |
+
<strong>π‘ Lighting Tips</strong><br>
|
1229 |
+
<a href='https://www.dementia.org.au/resources/good-design' target='_blank'>Illumination Best Practices</a>
|
1230 |
+
</div>
|
1231 |
+
<div>
|
1232 |
+
<strong>π¨ Color Contrast</strong><br>
|
1233 |
+
<a href='https://webaim.org/resources/contrastchecker/' target='_blank'>Online Contrast Checker</a>
|
1234 |
+
</div>
|
1235 |
+
</div>
|
1236 |
+
</div>
|
1237 |
+
""")
|
1238 |
+
|
1239 |
+
# Footer
|
1240 |
+
gr.HTML("""
|
1241 |
+
<div style='text-align: center; color: #6b7280; margin-top: 3rem; padding: 2rem; border-top: 1px solid #e5e7eb;'>
|
1242 |
+
<p><strong>NeuroNest v2.0</strong> β’ Enhanced AI-Powered Environmental Safety Analysis</p>
|
1243 |
+
<p style='font-size: 0.9rem;'>Creating safer spaces for cognitive health through computer vision and AI</p>
|
1244 |
+
<p style='font-size: 0.85rem; margin-top: 1rem;'>
|
1245 |
+
Β© 2024 Texas State University β’ Computer Science & Interior Design Departments<br>
|
1246 |
+
For research collaboration: neuronest@txstate.edu
|
1247 |
+
</p>
|
1248 |
+
</div>
|
1249 |
+
""")
|
1250 |
+
|
1251 |
+
# Event handlers
|
1252 |
analyze_button.click(
|
1253 |
fn=analyze_wrapper,
|
1254 |
inputs=[
|
|
|
1266 |
]
|
1267 |
)
|
1268 |
|
|
|
|
|
|
|
|
|
|
|
|
|
1269 |
return interface
|
1270 |
|
1271 |
########################################
|