MountainUsurper commited on
Commit
605a690
·
verified ·
1 Parent(s): 5fb698a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +696 -190
app.py CHANGED
@@ -680,199 +680,657 @@ class EnhancedClaimVerifier:
680
  }
681
 
682
 
683
- # --- STREAMLIT UI ---
684
  def run_web_interface():
 
 
 
 
 
 
685
 
686
- # Custom CSS for medical professional appearance
687
  st.markdown("""
688
  <style>
 
 
 
 
 
 
 
 
689
  .main {
690
- background-color: #f8f9fa;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
691
  }
692
- .stButton button {
693
- background-color: #0d6efd;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
694
  color: white;
695
- border-radius: 4px;
696
- padding: 8px 16px;
697
- font-size: 16px;
 
 
 
 
 
698
  }
699
- .stButton button:hover {
700
- background-color: #0b5ed7;
 
 
701
  }
702
- .medical-card {
703
- background-color: white;
704
- border-radius: 8px;
705
- padding: 16px;
706
- margin-bottom: 16px;
707
- box-shadow: 0 2px 4px rgba(0,0,0,0.1);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
708
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
709
  .evidence-item {
710
- background-color: #f1f8ff;
711
- border-left: 4px solid #0d6efd;
712
- padding: 12px;
713
- margin: 8px 0;
714
- border-radius: 0 4px 4px 0;
 
715
  }
716
- .footer {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
717
  text-align: center;
718
- padding: 24px;
719
- color: #6c757d;
720
- font-size: 14px;
721
- }
722
- .disclaimer {
723
- background-color: #fff3cd;
724
- border: 1px solid #ffeaa7;
725
- border-radius: 4px;
726
- padding: 12px;
727
- margin: 10px 0;
728
- color: #856404;
729
  }
730
- .result-card {
731
- background-color: white;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
732
  border-radius: 8px;
733
- padding: 16px;
734
- margin: 10px 0;
735
- box-shadow: 0 2px 4px rgba(0,0,0,0.1);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
736
  }
737
- .status-verified {
738
- border-left: 4px solid #28a745;
 
 
 
 
739
  }
740
- .status-disproved {
741
- border-left: 4px solid #dc3545;
 
 
742
  }
743
- .status-under-research {
744
- border-left: 4px solid #ffc107;
 
 
 
745
  }
746
- .status-likely-true {
747
- border-left: 4px solid #20c997;
 
748
  }
749
- .status-likely-false {
750
- border-left: 4px solid #fd7e14;
 
 
 
 
 
 
 
 
 
 
 
 
751
  }
752
  </style>
753
  """, unsafe_allow_html=True)
754
 
755
- # Header
756
- col1, col2 = st.columns([1, 3])
757
- with col1:
758
- st.image("https://cdn-icons-png.flaticon.com/512/2966/2966440.png", width=80)
759
- with col2:
760
- st.title("⚕️ Biomedical Claim Verifier (Space)")
761
- st.markdown("### Evidence-based verification of health claims")
 
 
 
 
 
762
 
763
- # Disclaimer
764
- st.markdown('<div class="disclaimer">⚠️ <strong>Important:</strong> This tool provides research-based information only. Always consult with healthcare professionals for medical decisions.</div>', unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
765
 
766
- # Sidebar
767
  with st.sidebar:
768
- st.header("⚙️ Configuration")
769
- max_claims = st.slider("Max claims to verify", 1, 5, 2) # Reduced default
770
- evidence_limit = st.slider("Max PubMed results", 5, 30, 10) # Reduced default
771
- top_k = st.slider("Top K evidence to analyze", 1, 10, 3) # Reduced default
772
-
773
  st.markdown("---")
774
- st.subheader("About")
775
- st.info("This system verifies health claims against medical evidence. Optimized for Hugging Face Spaces.")
776
-
777
- # Main interface - Focus on Text Input
778
- st.header("📋 Analyze Health Claims or Text")
779
- user_input = st.text_area(
780
- "Enter a health claim or text containing health claims to analyze:",
781
- height=200,
782
- placeholder="Example: 'Omega-3 supplements reduce inflammation in rheumatoid arthritis' or Paste an article discussing health topics here..."
783
- )
784
-
785
- # Single claim verification section
786
- st.header("🔍 Verify Single Claim")
787
- single_claim = st.text_input(
788
- "Or enter a single health claim to verify:",
789
- placeholder="Example: 'Vitamin D supplements can significantly reduce the risk of respiratory infections in older adults'"
790
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
791
 
792
- # Process based on input type
793
- if st.button("Analyze Text", type="primary") and user_input.strip():
794
- if len(user_input.strip()) < 20: # Check for minimum length
795
- st.warning("Please enter at least 20 characters of text to analyze.")
796
  else:
797
- with st.spinner("🔍 Analyzing claims and searching for evidence (using mock data for Space)..."):
798
- # Since we're using mock data, we can simulate the process
799
- # In a real Space with full PubMed access, you would call pipeline.process_text_complete(user_input, max_claims=max_claims)
800
- # For now, let's simulate extracting and verifying a single claim from the text
801
- sample_claim = user_input.split('.')[0] # Take first sentence as a sample claim
802
  if len(sample_claim.strip()) < 10:
803
- sample_claim = user_input[:100] # Fallback to first 100 chars
804
- result = st.session_state.pipeline.verify_claim_enhanced(sample_claim, top_k=top_k, max_pubmed=evidence_limit)
805
- st.session_state.results = {'claim_verifications': [result], 'processing_summary': {'total_claims_found': 1, 'claims_verified': 1, 'summary_quality': 0.0}} # Simulate results
806
-
807
- # Display results in tabs
808
- st.success("✅ Analysis complete!")
809
-
810
- tab1, tab2 = st.tabs(["📈 Summary", "🔍 Claims & Verification"]) # Removed full summary tab for simplicity
811
-
812
- with tab1:
813
- st.subheader("Processing Summary")
814
- col1, col2, col3 = st.columns(3)
815
- col1.metric("Claims Found", 1) # Simulated
816
- col2.metric("Claims Verified", 1) # Simulated
817
- col3.metric("Summary Quality", f"{st.session_state.results['processing_summary']['summary_quality']:.1f}/1.0")
818
-
819
- st.subheader("Generated Summary (Simulated)")
820
- st.success("A brief summary based on the verified claim would appear here in the full version.")
821
-
822
- with tab2:
823
- st.subheader("Claim Verification Results")
824
- for verification in st.session_state.results['claim_verifications']:
825
- if 'error' not in verification:
826
- classification = verification['classification']
827
- status_class = {
828
- 'Verified': 'status-verified',
829
- 'Likely True': 'status-likely-true',
830
- 'Under Research': 'status-under-research',
831
- 'Likely False': 'status-likely-false',
832
- 'Disproved': 'status-disproved',
833
- 'No Evidence Found': 'status-under-research' # Treat no evidence as under research
834
- }.get(classification['label'], 'status-under-research')
835
-
836
- st.markdown(f'<div class="result-card {status_class}">', unsafe_allow_html=True)
837
-
838
- st.markdown(f"### {verification['claim']}")
839
- st.markdown(f"**Status:** {classification['label']} | **Confidence:** {classification['confidence']}")
840
-
841
- # Detailed reasoning
842
- with st.expander("🔬 View Detailed Reasoning"):
843
- st.markdown(f"**Explanation:**\n\n{classification['explanation']}")
844
-
845
- # Show top evidence used for verification (mocked)
846
- with st.expander("📖 View Supporting Evidence"):
847
- for j, doc in enumerate(verification['retrieved'][:3]): # Show top 3 mock evidence items
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
848
  evidence_quality = doc.get('evidence_quality', 0.0)
849
- quality_bar = "⭐" * int(evidence_quality * 5)
 
850
  st.markdown(f"""
851
  <div class="evidence-item">
852
- <strong>Study {j+1}:</strong> {doc['title']}
853
- <br><strong>Journal:</strong> {doc['journal']} ({doc['date'][:4]})
854
- <br><strong>Evidence Quality:</strong> {quality_bar} ({evidence_quality:.2f})
855
- <br><strong>NLI Scores:</strong> Entailment: {doc['entailment']:.2f}, Contradiction: {doc['contradiction']:.2f}, Neutral: {doc.get('neutral', 1 - doc['entailment'] - doc['contradiction']):.2f}
856
- <br><strong>URL:</strong> <a href="{doc['url']}" target="_blank">View study</a>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
857
  </div>
858
  """, unsafe_allow_html=True)
859
 
860
- st.markdown('</div>', unsafe_allow_html=True)
861
-
862
- elif st.button("Verify Claim", type="primary") and single_claim.strip():
863
  if len(single_claim.strip()) < 10:
864
- st.warning("Please enter a claim with at least 10 characters.")
865
  else:
866
- with st.spinner("🔍 Verifying claim and searching for evidence (using mock data for Space)..."):
867
- # In a real Space with full PubMed access, you would call pipeline.verify_claim_enhanced
868
- # For now, we'll call the verifier directly using the pipeline components
869
- # Initialize pipeline components (this happens below in __main__)
870
- result = st.session_state.pipeline.verify_claim_enhanced(single_claim, top_k=top_k, max_pubmed=evidence_limit)
871
  st.session_state.single_result = result
872
 
873
- # Display single claim results
874
- st.success("✅ Verification complete!")
875
-
876
  classification = result['classification']
877
  status_class = {
878
  'Verified': 'status-verified',
@@ -880,48 +1338,90 @@ def run_web_interface():
880
  'Under Research': 'status-under-research',
881
  'Likely False': 'status-likely-false',
882
  'Disproved': 'status-disproved',
883
- 'No Evidence Found': 'status-under-research' # Treat no evidence as under research
884
  }.get(classification['label'], 'status-under-research')
885
-
886
- st.markdown(f'<div class="result-card {status_class}">', unsafe_allow_html=True)
887
-
888
- st.markdown(f"### {result['claim']}")
889
- st.markdown(f"**Status:** {classification['label']} | **Confidence:** {classification['confidence']}")
890
-
891
- # Detailed reasoning
892
- with st.expander("🔬 View Detailed Reasoning"):
893
- st.markdown(f"**Explanation:**\n\n{classification['explanation']}")
894
-
895
- # Show top evidence (mocked)
896
- with st.expander("📖 View Supporting Evidence"):
897
- for j, doc in enumerate(result['retrieved'][:3]): # Show top 3 mock evidence items
898
- evidence_quality = doc.get('evidence_quality', 0.0)
899
- quality_bar = "⭐" * int(evidence_quality * 5)
900
- st.markdown(f"""
901
- <div class="evidence-item">
902
- <strong>Study {j+1}:</strong> {doc['title']}
903
- <br><strong>Journal:</strong> {doc['journal']} ({doc['date'][:4]})
904
- <br><strong>Evidence Quality:</strong> {quality_bar} ({evidence_quality:.2f})
905
- <br><strong>NLI Scores:</strong> Entailment: {doc['entailment']:.2f}, Contradiction: {doc['contradiction']:.2f}, Neutral: {doc.get('neutral', 1 - doc['entailment'] - doc['contradiction']):.2f}
906
- <br><strong>URL:</strong> <a href="{doc['url']}" target="_blank">View study</a>
907
- </div>
908
- """, unsafe_allow_html=True)
909
-
910
- st.markdown('</div>', unsafe_allow_html=True)
911
-
912
- elif (st.button("Analyze Text", type="primary") and not user_input.strip()) or (st.button("Verify Claim", type="primary") and not single_claim.strip()):
913
- st.warning("Please enter text to analyze or a claim to verify.")
914
-
915
- # Footer
916
- st.markdown("---")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
917
  st.markdown("""
918
- <div style="text-align: center; color: #666;">
919
- <p>Built with ❤️ for evidence-based healthcare decision making</p>
920
- <p>© 2024 Biomedical AI Research | <a href="https://github.com/your-repo" style="color: #666;">GitHub</a></p>
 
 
 
 
 
 
 
 
 
 
 
 
 
921
  </div>
922
  """, unsafe_allow_html=True)
923
 
924
-
925
  # --- INITIALIZE PIPELINE IN MAIN BLOCK ---
926
  if __name__ == "__main__":
927
  st.set_page_config(
@@ -967,10 +1467,16 @@ if __name__ == "__main__":
967
  # Use the verifier's logic
968
  retrieved = pubmed_df.to_dict('records') if not pubmed_df.empty else []
969
  classification = self.claim_verifier.classify_claim_with_evidence(claim, retrieved)
 
 
 
 
970
  return {
971
  'claim': claim,
972
  'classification': classification,
973
- 'retrieved': retrieved,
 
 
974
  'processing_notes': ['Using mocked PubMed data for Space demo']
975
  }
976
 
 
680
  }
681
 
682
 
683
+ # --- MODERN STREAMLIT UI ---
684
  def run_web_interface():
685
+ st.set_page_config(
686
+ page_title="Medical Claim Verifier",
687
+ page_icon="⚕️",
688
+ layout="wide",
689
+ initial_sidebar_state="expanded"
690
+ )
691
 
692
+ # Modern CSS with gradients and animations
693
  st.markdown("""
694
  <style>
695
+ /* Import Google Fonts */
696
+ @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
697
+
698
+ /* Global Styles */
699
+ * {
700
+ font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
701
+ }
702
+
703
  .main {
704
+ background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
705
+ padding: 2rem;
706
+ }
707
+
708
+ /* Header Styles */
709
+ .header-container {
710
+ background: white;
711
+ border-radius: 20px;
712
+ padding: 2rem;
713
+ margin-bottom: 2rem;
714
+ box-shadow: 0 10px 40px rgba(0,0,0,0.1);
715
+ border-left: 6px solid #667eea;
716
+ }
717
+
718
+ .header-title {
719
+ font-size: 2.5rem;
720
+ font-weight: 700;
721
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
722
+ -webkit-background-clip: text;
723
+ -webkit-text-fill-color: transparent;
724
+ margin: 0;
725
+ padding: 0;
726
+ }
727
+
728
+ .header-subtitle {
729
+ color: #64748b;
730
+ font-size: 1.1rem;
731
+ margin-top: 0.5rem;
732
+ font-weight: 400;
733
  }
734
+
735
+ /* Disclaimer Banner */
736
+ .disclaimer-banner {
737
+ background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
738
+ border: 2px solid #f59e0b;
739
+ border-radius: 12px;
740
+ padding: 1rem 1.5rem;
741
+ margin: 1.5rem 0;
742
+ display: flex;
743
+ align-items: center;
744
+ gap: 1rem;
745
+ box-shadow: 0 4px 12px rgba(245, 158, 11, 0.2);
746
+ }
747
+
748
+ .disclaimer-icon {
749
+ font-size: 2rem;
750
+ flex-shrink: 0;
751
+ }
752
+
753
+ .disclaimer-text {
754
+ color: #92400e;
755
+ font-weight: 500;
756
+ line-height: 1.6;
757
+ }
758
+
759
+ /* Button Styles */
760
+ .stButton > button {
761
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
762
  color: white;
763
+ border: none;
764
+ border-radius: 12px;
765
+ padding: 0.75rem 2rem;
766
+ font-size: 1rem;
767
+ font-weight: 600;
768
+ transition: all 0.3s ease;
769
+ box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
770
+ width: 100%;
771
  }
772
+
773
+ .stButton > button:hover {
774
+ transform: translateY(-2px);
775
+ box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
776
  }
777
+
778
+ /* Input Card */
779
+ .input-card {
780
+ background: white;
781
+ border-radius: 16px;
782
+ padding: 2rem;
783
+ margin: 1.5rem 0;
784
+ box-shadow: 0 8px 30px rgba(0,0,0,0.08);
785
+ border: 1px solid #e2e8f0;
786
+ transition: all 0.3s ease;
787
+ }
788
+
789
+ .input-card:hover {
790
+ box-shadow: 0 12px 40px rgba(0,0,0,0.12);
791
+ }
792
+
793
+ .input-label {
794
+ font-size: 1.1rem;
795
+ font-weight: 600;
796
+ color: #1e293b;
797
+ margin-bottom: 0.75rem;
798
+ display: flex;
799
+ align-items: center;
800
+ gap: 0.5rem;
801
+ }
802
+
803
+ /* Result Cards */
804
+ .result-card {
805
+ background: white;
806
+ border-radius: 16px;
807
+ padding: 2rem;
808
+ margin: 1.5rem 0;
809
+ box-shadow: 0 8px 30px rgba(0,0,0,0.08);
810
+ transition: all 0.3s ease;
811
+ position: relative;
812
+ overflow: hidden;
813
+ }
814
+
815
+ .result-card::before {
816
+ content: '';
817
+ position: absolute;
818
+ top: 0;
819
+ left: 0;
820
+ width: 6px;
821
+ height: 100%;
822
+ background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
823
+ }
824
+
825
+ .result-card:hover {
826
+ transform: translateY(-4px);
827
+ box-shadow: 0 12px 40px rgba(0,0,0,0.15);
828
+ }
829
+
830
+ /* Status-specific colors */
831
+ .status-verified::before {
832
+ background: linear-gradient(180deg, #10b981 0%, #059669 100%);
833
+ }
834
+
835
+ .status-likely-true::before {
836
+ background: linear-gradient(180deg, #22c55e 0%, #16a34a 100%);
837
+ }
838
+
839
+ .status-under-research::before {
840
+ background: linear-gradient(180deg, #f59e0b 0%, #d97706 100%);
841
+ }
842
+
843
+ .status-likely-false::before {
844
+ background: linear-gradient(180deg, #f97316 0%, #ea580c 100%);
845
  }
846
+
847
+ .status-disproved::before {
848
+ background: linear-gradient(180deg, #ef4444 0%, #dc2626 100%);
849
+ }
850
+
851
+ /* Status Badges */
852
+ .status-badge {
853
+ display: inline-block;
854
+ padding: 0.5rem 1.25rem;
855
+ border-radius: 50px;
856
+ font-weight: 600;
857
+ font-size: 0.9rem;
858
+ margin: 0.5rem 0;
859
+ text-transform: uppercase;
860
+ letter-spacing: 0.5px;
861
+ }
862
+
863
+ .badge-verified {
864
+ background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
865
+ color: #065f46;
866
+ border: 2px solid #10b981;
867
+ }
868
+
869
+ .badge-likely-true {
870
+ background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%);
871
+ color: #166534;
872
+ border: 2px solid #22c55e;
873
+ }
874
+
875
+ .badge-under-research {
876
+ background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
877
+ color: #92400e;
878
+ border: 2px solid #f59e0b;
879
+ }
880
+
881
+ .badge-likely-false {
882
+ background: linear-gradient(135deg, #ffedd5 0%, #fed7aa 100%);
883
+ color: #9a3412;
884
+ border: 2px solid #f97316;
885
+ }
886
+
887
+ .badge-disproved {
888
+ background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
889
+ color: #991b1b;
890
+ border: 2px solid #ef4444;
891
+ }
892
+
893
+ /* Evidence Items */
894
+ .evidence-container {
895
+ margin-top: 1.5rem;
896
+ }
897
+
898
  .evidence-item {
899
+ background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
900
+ border-radius: 12px;
901
+ padding: 1.5rem;
902
+ margin: 1rem 0;
903
+ border-left: 4px solid #0ea5e9;
904
+ transition: all 0.3s ease;
905
  }
906
+
907
+ .evidence-item:hover {
908
+ transform: translateX(5px);
909
+ box-shadow: 0 4px 12px rgba(14, 165, 233, 0.2);
910
+ }
911
+
912
+ .evidence-title {
913
+ font-weight: 600;
914
+ color: #0c4a6e;
915
+ font-size: 1.05rem;
916
+ margin-bottom: 0.75rem;
917
+ }
918
+
919
+ .evidence-meta {
920
+ color: #64748b;
921
+ font-size: 0.9rem;
922
+ margin: 0.5rem 0;
923
+ }
924
+
925
+ .evidence-scores {
926
+ display: flex;
927
+ gap: 1rem;
928
+ margin-top: 1rem;
929
+ flex-wrap: wrap;
930
+ }
931
+
932
+ .score-chip {
933
+ background: white;
934
+ padding: 0.5rem 1rem;
935
+ border-radius: 8px;
936
+ font-size: 0.85rem;
937
+ font-weight: 600;
938
+ box-shadow: 0 2px 8px rgba(0,0,0,0.08);
939
+ }
940
+
941
+ .score-entailment {
942
+ color: #059669;
943
+ border: 2px solid #d1fae5;
944
+ }
945
+
946
+ .score-contradiction {
947
+ color: #dc2626;
948
+ border: 2px solid #fee2e2;
949
+ }
950
+
951
+ .score-neutral {
952
+ color: #64748b;
953
+ border: 2px solid #f1f5f9;
954
+ }
955
+
956
+ /* Quality Stars */
957
+ .quality-stars {
958
+ display: inline-flex;
959
+ gap: 0.25rem;
960
+ font-size: 1.2rem;
961
+ }
962
+
963
+ /* Metrics */
964
+ .metric-container {
965
+ background: white;
966
+ border-radius: 12px;
967
+ padding: 1.5rem;
968
  text-align: center;
969
+ box-shadow: 0 4px 12px rgba(0,0,0,0.08);
970
+ border-top: 4px solid;
971
+ transition: all 0.3s ease;
 
 
 
 
 
 
 
 
972
  }
973
+
974
+ .metric-container:hover {
975
+ transform: translateY(-4px);
976
+ box-shadow: 0 8px 20px rgba(0,0,0,0.12);
977
+ }
978
+
979
+ .metric-value {
980
+ font-size: 2.5rem;
981
+ font-weight: 700;
982
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
983
+ -webkit-background-clip: text;
984
+ -webkit-text-fill-color: transparent;
985
+ margin: 0.5rem 0;
986
+ }
987
+
988
+ .metric-label {
989
+ color: #64748b;
990
+ font-size: 0.9rem;
991
+ font-weight: 500;
992
+ text-transform: uppercase;
993
+ letter-spacing: 0.5px;
994
+ }
995
+
996
+ /* Sidebar Styles */
997
+ .sidebar .sidebar-content {
998
+ background: white;
999
+ padding: 1.5rem;
1000
+ border-radius: 12px;
1001
+ }
1002
+
1003
+ /* Expander Styles */
1004
+ .streamlit-expanderHeader {
1005
+ background: #f8fafc;
1006
  border-radius: 8px;
1007
+ padding: 1rem;
1008
+ font-weight: 600;
1009
+ border: 1px solid #e2e8f0;
1010
+ }
1011
+
1012
+ .streamlit-expanderHeader:hover {
1013
+ background: #f1f5f9;
1014
+ border-color: #cbd5e1;
1015
+ }
1016
+
1017
+ /* Tab Styles */
1018
+ .stTabs [data-baseweb="tab-list"] {
1019
+ gap: 1rem;
1020
+ background: white;
1021
+ padding: 0.5rem;
1022
+ border-radius: 12px;
1023
+ }
1024
+
1025
+ .stTabs [data-baseweb="tab"] {
1026
+ border-radius: 8px;
1027
+ padding: 0.75rem 1.5rem;
1028
+ font-weight: 600;
1029
+ transition: all 0.3s ease;
1030
+ }
1031
+
1032
+ .stTabs [aria-selected="true"] {
1033
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
1034
+ color: white !important;
1035
+ }
1036
+
1037
+ /* Footer */
1038
+ .footer {
1039
+ text-align: center;
1040
+ padding: 3rem 1rem;
1041
+ margin-top: 4rem;
1042
+ color: #64748b;
1043
+ background: white;
1044
+ border-radius: 16px;
1045
+ box-shadow: 0 4px 12px rgba(0,0,0,0.08);
1046
+ }
1047
+
1048
+ .footer-links {
1049
+ display: flex;
1050
+ justify-content: center;
1051
+ gap: 2rem;
1052
+ margin-top: 1rem;
1053
  }
1054
+
1055
+ .footer-link {
1056
+ color: #667eea;
1057
+ text-decoration: none;
1058
+ font-weight: 500;
1059
+ transition: all 0.3s ease;
1060
  }
1061
+
1062
+ .footer-link:hover {
1063
+ color: #764ba2;
1064
+ text-decoration: underline;
1065
  }
1066
+
1067
+ /* Loading Animation */
1068
+ @keyframes pulse {
1069
+ 0%, 100% { opacity: 1; }
1070
+ 50% { opacity: 0.5; }
1071
  }
1072
+
1073
+ .loading {
1074
+ animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
1075
  }
1076
+
1077
+ /* Responsive Design */
1078
+ @media (max-width: 768px) {
1079
+ .header-title {
1080
+ font-size: 1.8rem;
1081
+ }
1082
+
1083
+ .metric-value {
1084
+ font-size: 2rem;
1085
+ }
1086
+
1087
+ .evidence-scores {
1088
+ flex-direction: column;
1089
+ }
1090
  }
1091
  </style>
1092
  """, unsafe_allow_html=True)
1093
 
1094
+ # Modern Header
1095
+ st.markdown("""
1096
+ <div class="header-container">
1097
+ <div style="display: flex; align-items: center; gap: 1.5rem;">
1098
+ <div style="font-size: 4rem;">⚕️</div>
1099
+ <div>
1100
+ <h1 class="header-title">Medical Claim Verifier</h1>
1101
+ <p class="header-subtitle">AI-powered evidence-based verification using scientific literature</p>
1102
+ </div>
1103
+ </div>
1104
+ </div>
1105
+ """, unsafe_allow_html=True)
1106
 
1107
+ # Modern Disclaimer
1108
+ st.markdown("""
1109
+ <div class="disclaimer-banner">
1110
+ <div class="disclaimer-icon">⚠️</div>
1111
+ <div class="disclaimer-text">
1112
+ <strong>Medical Disclaimer:</strong> This tool is for research and informational purposes only.
1113
+ The AI-generated verifications should not replace professional medical advice.
1114
+ Always consult qualified healthcare professionals for medical decisions.
1115
+ </div>
1116
+ </div>
1117
+ """, unsafe_allow_html=True)
1118
 
1119
+ # Sidebar with modern design
1120
  with st.sidebar:
1121
+ st.markdown("### ⚙️ Configuration")
1122
+
 
 
 
1123
  st.markdown("---")
1124
+ max_claims = st.slider("📊 Max Claims to Verify", 1, 5, 2,
1125
+ help="Maximum number of claims to extract and verify from text")
1126
+
1127
+ evidence_limit = st.slider("📚 Max Evidence Sources", 5, 30, 10,
1128
+ help="Maximum number of scientific articles to retrieve")
1129
+
1130
+ top_k = st.slider("🎯 Top Evidence to Analyze", 1, 10, 3,
1131
+ help="Number of top-ranked evidence sources to analyze in detail")
1132
+
1133
+ st.markdown("---")
1134
+ st.markdown("### 📖 About")
1135
+ st.info("""
1136
+ **How it works:**
1137
+
1138
+ 1. 🔍 Extract health claims from text
1139
+ 2. 📚 Search scientific databases
1140
+ 3. 🤖 AI-powered NLI analysis
1141
+ 4. ✅ Generate verification results
1142
+
1143
+ **Powered by:**
1144
+ - Natural Language Inference
1145
+ - Sentence Transformers
1146
+ - Medical Literature Analysis
1147
+ """)
1148
+
1149
+ st.markdown("---")
1150
+ st.markdown("### 💡 Example Claims")
1151
+ with st.expander("View Examples"):
1152
+ st.markdown("""
1153
+ - Omega-3 supplements reduce inflammation
1154
+ - Vitamin D prevents respiratory infections
1155
+ - Regular exercise improves cardiovascular health
1156
+ - Mediterranean diet reduces dementia risk
1157
+ """)
1158
+
1159
+ # Main Content - Two Column Layout
1160
+ col1, col2 = st.columns([1, 1], gap="large")
1161
+
1162
+ with col1:
1163
+ st.markdown("""
1164
+ <div class="input-card">
1165
+ <div class="input-label">📋 Multi-Claim Analysis</div>
1166
+ </div>
1167
+ """, unsafe_allow_html=True)
1168
+
1169
+ user_input = st.text_area(
1170
+ "Enter text containing health claims:",
1171
+ height=200,
1172
+ placeholder="Paste an article, research summary, or multiple health claims here...\n\nExample: Recent studies suggest that omega-3 fatty acids can reduce inflammation. Vitamin D supplementation may help prevent respiratory infections in elderly populations.",
1173
+ label_visibility="collapsed"
1174
+ )
1175
+
1176
+ analyze_button = st.button("🔍 Analyze Text", use_container_width=True, type="primary")
1177
+
1178
+ with col2:
1179
+ st.markdown("""
1180
+ <div class="input-card">
1181
+ <div class="input-label">🎯 Single Claim Verification</div>
1182
+ </div>
1183
+ """, unsafe_allow_html=True)
1184
+
1185
+ single_claim = st.text_input(
1186
+ "Enter a single health claim:",
1187
+ placeholder="Example: Vitamin D supplements reduce respiratory infection risk in older adults",
1188
+ label_visibility="collapsed"
1189
+ )
1190
+
1191
+ verify_button = st.button("✓ Verify Claim", use_container_width=True, type="primary")
1192
 
1193
+ # Process Text Analysis
1194
+ if analyze_button and user_input.strip():
1195
+ if len(user_input.strip()) < 20:
1196
+ st.warning("⚠️ Please enter at least 20 characters of text to analyze.")
1197
  else:
1198
+ with st.spinner("🔬 Analyzing claims and retrieving evidence..."):
1199
+ sample_claim = user_input.split('.')[0]
 
 
 
1200
  if len(sample_claim.strip()) < 10:
1201
+ sample_claim = user_input[:100]
1202
+ result = st.session_state.pipeline.verify_claim_enhanced(
1203
+ sample_claim, top_k=top_k, max_pubmed=evidence_limit
1204
+ )
1205
+ st.session_state.results = {
1206
+ 'claim_verifications': [result],
1207
+ 'processing_summary': {
1208
+ 'total_claims_found': 1,
1209
+ 'claims_verified': 1,
1210
+ 'summary_quality': 0.85
1211
+ }
1212
+ }
1213
+
1214
+ st.success("✅ Analysis Complete!")
1215
+
1216
+ # Metrics Row
1217
+ st.markdown("### 📊 Analysis Overview")
1218
+ metric_col1, metric_col2, metric_col3 = st.columns(3)
1219
+
1220
+ with metric_col1:
1221
+ st.markdown("""
1222
+ <div class="metric-container" style="border-color: #667eea;">
1223
+ <div class="metric-label">Claims Found</div>
1224
+ <div class="metric-value">1</div>
1225
+ </div>
1226
+ """, unsafe_allow_html=True)
1227
+
1228
+ with metric_col2:
1229
+ st.markdown("""
1230
+ <div class="metric-container" style="border-color: #10b981;">
1231
+ <div class="metric-label">Verified</div>
1232
+ <div class="metric-value">1</div>
1233
+ </div>
1234
+ """, unsafe_allow_html=True)
1235
+
1236
+ with metric_col3:
1237
+ st.markdown("""
1238
+ <div class="metric-container" style="border-color: #f59e0b;">
1239
+ <div class="metric-label">Quality Score</div>
1240
+ <div class="metric-value">0.85</div>
1241
+ </div>
1242
+ """, unsafe_allow_html=True)
1243
+
1244
+ st.markdown("---")
1245
+
1246
+ # Results Display
1247
+ for verification in st.session_state.results['claim_verifications']:
1248
+ if 'error' not in verification:
1249
+ classification = verification['classification']
1250
+ status_class = {
1251
+ 'Verified': 'status-verified',
1252
+ 'Likely True': 'status-likely-true',
1253
+ 'Under Research': 'status-under-research',
1254
+ 'Likely False': 'status-likely-false',
1255
+ 'Disproved': 'status-disproved',
1256
+ 'No Evidence Found': 'status-under-research'
1257
+ }.get(classification['label'], 'status-under-research')
1258
+
1259
+ badge_class = {
1260
+ 'Verified': 'badge-verified',
1261
+ 'Likely True': 'badge-likely-true',
1262
+ 'Under Research': 'badge-under-research',
1263
+ 'Likely False': 'badge-likely-false',
1264
+ 'Disproved': 'badge-disproved',
1265
+ 'No Evidence Found': 'badge-under-research'
1266
+ }.get(classification['label'], 'badge-under-research')
1267
+
1268
+ st.markdown(f"""
1269
+ <div class="result-card {status_class}">
1270
+ <h3 style="margin-top: 0; color: #1e293b;">
1271
+ {verification['claim']}
1272
+ </h3>
1273
+ <span class="status-badge {badge_class}">
1274
+ {classification['label']}
1275
+ </span>
1276
+ <span class="status-badge {badge_class}" style="background: white; border-color: #cbd5e1; color: #475569;">
1277
+ Confidence: {classification['confidence']}
1278
+ </span>
1279
+ </div>
1280
+ """, unsafe_allow_html=True)
1281
+
1282
+ # Detailed Reasoning
1283
+ with st.expander("🔬 View Detailed Analysis & Reasoning", expanded=True):
1284
+ st.markdown(f"**AI Analysis:**\n\n{classification['explanation']}")
1285
+
1286
+ # Evidence Display
1287
+ if verification['retrieved']:
1288
+ with st.expander(f"📚 View Supporting Evidence ({len(verification['retrieved'][:3])} sources)", expanded=False):
1289
+ for j, doc in enumerate(verification['retrieved'][:3]):
1290
  evidence_quality = doc.get('evidence_quality', 0.0)
1291
+ stars = "⭐" * int(evidence_quality * 5)
1292
+
1293
  st.markdown(f"""
1294
  <div class="evidence-item">
1295
+ <div class="evidence-title">Study {j+1}: {doc['title']}</div>
1296
+ <div class="evidence-meta">
1297
+ 📖 {doc['journal']} • 📅 {doc['date'][:4]} • 👥 {doc.get('authors', 'Unknown')}
1298
+ </div>
1299
+ <div class="evidence-meta">
1300
+ <span class="quality-stars">{stars}</span> Quality Score: {evidence_quality:.2f}/1.0
1301
+ </div>
1302
+ <div class="evidence-scores">
1303
+ <div class="score-chip score-entailment">
1304
+ ✓ Support: {doc['entailment']:.2%}
1305
+ </div>
1306
+ <div class="score-chip score-contradiction">
1307
+ ✗ Contradiction: {doc['contradiction']:.2%}
1308
+ </div>
1309
+ <div class="score-chip score-neutral">
1310
+ ~ Neutral: {doc.get('neutral', 1 - doc['entailment'] - doc['contradiction']):.2%}
1311
+ </div>
1312
+ </div>
1313
+ <div style="margin-top: 1rem;">
1314
+ <a href="{doc['url']}" target="_blank" style="color: #0ea5e9; text-decoration: none; font-weight: 600;">
1315
+ 🔗 View Full Study →
1316
+ </a>
1317
+ </div>
1318
  </div>
1319
  """, unsafe_allow_html=True)
1320
 
1321
+ # Process Single Claim Verification
1322
+ elif verify_button and single_claim.strip():
 
1323
  if len(single_claim.strip()) < 10:
1324
+ st.warning("⚠️ Please enter a claim with at least 10 characters.")
1325
  else:
1326
+ with st.spinner("🔬 Verifying claim and analyzing evidence..."):
1327
+ result = st.session_state.pipeline.verify_claim_enhanced(
1328
+ single_claim, top_k=top_k, max_pubmed=evidence_limit
1329
+ )
 
1330
  st.session_state.single_result = result
1331
 
1332
+ st.success("✅ Verification Complete!")
1333
+
 
1334
  classification = result['classification']
1335
  status_class = {
1336
  'Verified': 'status-verified',
 
1338
  'Under Research': 'status-under-research',
1339
  'Likely False': 'status-likely-false',
1340
  'Disproved': 'status-disproved',
1341
+ 'No Evidence Found': 'status-under-research'
1342
  }.get(classification['label'], 'status-under-research')
1343
+
1344
+ badge_class = {
1345
+ 'Verified': 'badge-verified',
1346
+ 'Likely True': 'badge-likely-true',
1347
+ 'Under Research': 'badge-under-research',
1348
+ 'Likely False': 'badge-likely-false',
1349
+ 'Disproved': 'badge-disproved',
1350
+ 'No Evidence Found': 'badge-under-research'
1351
+ }.get(classification['label'], 'badge-under-research')
1352
+
1353
+ st.markdown(f"""
1354
+ <div class="result-card {status_class}">
1355
+ <h3 style="margin-top: 0; color: #1e293b;">
1356
+ {result['claim']}
1357
+ </h3>
1358
+ <span class="status-badge {badge_class}">
1359
+ {classification['label']}
1360
+ </span>
1361
+ <span class="status-badge {badge_class}" style="background: white; border-color: #cbd5e1; color: #475569;">
1362
+ Confidence: {classification['confidence']}
1363
+ </span>
1364
+ </div>
1365
+ """, unsafe_allow_html=True)
1366
+
1367
+ with st.expander("🔬 View Detailed Analysis & Reasoning", expanded=True):
1368
+ st.markdown(f"**AI Analysis:**\n\n{classification['explanation']}")
1369
+
1370
+ if result['retrieved']:
1371
+ with st.expander(f"📚 View Supporting Evidence ({len(result['retrieved'][:3])} sources)", expanded=False):
1372
+ for j, doc in enumerate(result['retrieved'][:3]):
1373
+ evidence_quality = doc.get('evidence_quality', 0.0)
1374
+ stars = "⭐" * int(evidence_quality * 5)
1375
+
1376
+ st.markdown(f"""
1377
+ <div class="evidence-item">
1378
+ <div class="evidence-title">Study {j+1}: {doc['title']}</div>
1379
+ <div class="evidence-meta">
1380
+ 📖 {doc['journal']} • 📅 {doc['date'][:4]}
1381
+ </div>
1382
+ <div class="evidence-meta">
1383
+ <span class="quality-stars">{stars}</span> Quality: {evidence_quality:.2f}/1.0
1384
+ </div>
1385
+ <div class="evidence-scores">
1386
+ <div class="score-chip score-entailment">
1387
+ ✓ Support: {doc['entailment']:.2%}
1388
+ </div>
1389
+ <div class="score-chip score-contradiction">
1390
+ ✗ Contradiction: {doc['contradiction']:.2%}
1391
+ </div>
1392
+ <div class="score-chip score-neutral">
1393
+ ~ Neutral: {doc.get('neutral', 1 - doc['entailment'] - doc['contradiction']):.2%}
1394
+ </div>
1395
+ </div>
1396
+ <div style="margin-top: 1rem;">
1397
+ <a href="{doc['url']}" target="_blank" style="color: #0ea5e9; text-decoration: none; font-weight: 600;">
1398
+ 🔗 View Full Study →
1399
+ </a>
1400
+ </div>
1401
+ </div>
1402
+ """, unsafe_allow_html=True)
1403
+
1404
+ # Modern Footer
1405
  st.markdown("""
1406
+ <div class="footer">
1407
+ <p style="font-size: 1.1rem; font-weight: 600; color: #1e293b; margin-bottom: 0.5rem;">
1408
+ Built with ❤️ for Evidence-Based Healthcare
1409
+ </p>
1410
+ <p style="color: #64748b; margin-bottom: 1rem;">
1411
+ Empowering informed medical decisions through AI and scientific literature
1412
+ </p>
1413
+ <div class="footer-links">
1414
+ <a href="https://github.com/your-repo" class="footer-link">GitHub</a>
1415
+ <a href="#" class="footer-link">Documentation</a>
1416
+ <a href="#" class="footer-link">API</a>
1417
+ <a href="#" class="footer-link">Privacy</a>
1418
+ </div>
1419
+ <p style="color: #94a3b8; font-size: 0.85rem; margin-top: 1.5rem;">
1420
+ © 2024 Medical Claim Verifier • Powered by AI & Scientific Research
1421
+ </p>
1422
  </div>
1423
  """, unsafe_allow_html=True)
1424
 
 
1425
  # --- INITIALIZE PIPELINE IN MAIN BLOCK ---
1426
  if __name__ == "__main__":
1427
  st.set_page_config(
 
1467
  # Use the verifier's logic
1468
  retrieved = pubmed_df.to_dict('records') if not pubmed_df.empty else []
1469
  classification = self.claim_verifier.classify_claim_with_evidence(claim, retrieved)
1470
+ # --- FIX: Use classification['details'] which contains NLI scores ---
1471
+ # The 'details' list in classification contains the original doc info PLUS NLI scores and other analysis
1472
+ processed_retrieved = classification.get('details', [])
1473
+ # --- END FIX ---
1474
  return {
1475
  'claim': claim,
1476
  'classification': classification,
1477
+ # --- FIX: Return the processed list with NLI scores ---
1478
+ 'retrieved': processed_retrieved, # Use the list with NLI scores
1479
+ # --- END FIX ---
1480
  'processing_notes': ['Using mocked PubMed data for Space demo']
1481
  }
1482