Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -680,199 +680,657 @@ class EnhancedClaimVerifier:
|
|
| 680 |
}
|
| 681 |
|
| 682 |
|
| 683 |
-
# --- STREAMLIT UI ---
|
| 684 |
def run_web_interface():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 685 |
|
| 686 |
-
#
|
| 687 |
st.markdown("""
|
| 688 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 689 |
.main {
|
| 690 |
-
background
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 691 |
}
|
| 692 |
-
|
| 693 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 694 |
color: white;
|
| 695 |
-
border
|
| 696 |
-
|
| 697 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 698 |
}
|
| 699 |
-
|
| 700 |
-
|
|
|
|
|
|
|
| 701 |
}
|
| 702 |
-
|
| 703 |
-
|
| 704 |
-
|
| 705 |
-
|
| 706 |
-
|
| 707 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 708 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 709 |
.evidence-item {
|
| 710 |
-
background
|
| 711 |
-
border-
|
| 712 |
-
padding:
|
| 713 |
-
margin:
|
| 714 |
-
border-
|
|
|
|
| 715 |
}
|
| 716 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 717 |
text-align: center;
|
| 718 |
-
|
| 719 |
-
|
| 720 |
-
|
| 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 |
-
|
| 731 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 732 |
border-radius: 8px;
|
| 733 |
-
padding:
|
| 734 |
-
|
| 735 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 736 |
}
|
| 737 |
-
|
| 738 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 739 |
}
|
| 740 |
-
|
| 741 |
-
|
|
|
|
|
|
|
| 742 |
}
|
| 743 |
-
|
| 744 |
-
|
|
|
|
|
|
|
|
|
|
| 745 |
}
|
| 746 |
-
|
| 747 |
-
|
|
|
|
| 748 |
}
|
| 749 |
-
|
| 750 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 751 |
}
|
| 752 |
</style>
|
| 753 |
""", unsafe_allow_html=True)
|
| 754 |
|
| 755 |
-
# Header
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
|
| 759 |
-
|
| 760 |
-
|
| 761 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 762 |
|
| 763 |
-
# Disclaimer
|
| 764 |
-
st.markdown(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 765 |
|
| 766 |
-
# Sidebar
|
| 767 |
with st.sidebar:
|
| 768 |
-
st.
|
| 769 |
-
|
| 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.
|
| 775 |
-
|
| 776 |
-
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
|
| 781 |
-
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
|
| 785 |
-
|
| 786 |
-
|
| 787 |
-
|
| 788 |
-
|
| 789 |
-
|
| 790 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 791 |
|
| 792 |
-
# Process
|
| 793 |
-
if
|
| 794 |
-
if len(user_input.strip()) < 20:
|
| 795 |
-
st.warning("Please enter at least 20 characters of text to analyze.")
|
| 796 |
else:
|
| 797 |
-
with st.spinner("
|
| 798 |
-
|
| 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]
|
| 804 |
-
result = st.session_state.pipeline.verify_claim_enhanced(
|
| 805 |
-
|
| 806 |
-
|
| 807 |
-
|
| 808 |
-
|
| 809 |
-
|
| 810 |
-
|
| 811 |
-
|
| 812 |
-
|
| 813 |
-
|
| 814 |
-
|
| 815 |
-
|
| 816 |
-
|
| 817 |
-
|
| 818 |
-
|
| 819 |
-
|
| 820 |
-
|
| 821 |
-
|
| 822 |
-
with
|
| 823 |
-
st.
|
| 824 |
-
|
| 825 |
-
|
| 826 |
-
|
| 827 |
-
|
| 828 |
-
|
| 829 |
-
|
| 830 |
-
|
| 831 |
-
|
| 832 |
-
|
| 833 |
-
|
| 834 |
-
|
| 835 |
-
|
| 836 |
-
|
| 837 |
-
|
| 838 |
-
|
| 839 |
-
|
| 840 |
-
|
| 841 |
-
|
| 842 |
-
|
| 843 |
-
|
| 844 |
-
|
| 845 |
-
|
| 846 |
-
|
| 847 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 848 |
evidence_quality = doc.get('evidence_quality', 0.0)
|
| 849 |
-
|
|
|
|
| 850 |
st.markdown(f"""
|
| 851 |
<div class="evidence-item">
|
| 852 |
-
<
|
| 853 |
-
<
|
| 854 |
-
|
| 855 |
-
<
|
| 856 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 857 |
</div>
|
| 858 |
""", unsafe_allow_html=True)
|
| 859 |
|
| 860 |
-
|
| 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("
|
| 867 |
-
|
| 868 |
-
|
| 869 |
-
|
| 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 |
-
|
| 874 |
-
|
| 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'
|
| 884 |
}.get(classification['label'], 'status-under-research')
|
| 885 |
-
|
| 886 |
-
|
| 887 |
-
|
| 888 |
-
|
| 889 |
-
|
| 890 |
-
|
| 891 |
-
|
| 892 |
-
|
| 893 |
-
|
| 894 |
-
|
| 895 |
-
|
| 896 |
-
|
| 897 |
-
|
| 898 |
-
|
| 899 |
-
|
| 900 |
-
|
| 901 |
-
|
| 902 |
-
|
| 903 |
-
|
| 904 |
-
|
| 905 |
-
|
| 906 |
-
|
| 907 |
-
|
| 908 |
-
|
| 909 |
-
|
| 910 |
-
|
| 911 |
-
|
| 912 |
-
|
| 913 |
-
|
| 914 |
-
|
| 915 |
-
|
| 916 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 917 |
st.markdown("""
|
| 918 |
-
<div
|
| 919 |
-
<p
|
| 920 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
| 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 |
|