File size: 5,902 Bytes
3e9c053
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
document.getElementById("newsImage").addEventListener("change", function(e) {
    const fileName = e.target.files[0] ? e.target.files[0].name : "Upload Image for Tampering Check";
    document.querySelector(".file-upload-text").textContent = fileName;
});

document.getElementById("verifyForm").addEventListener("submit", async function(e) {
    e.preventDefault();
    
    const form = e.target;
    const formData = new FormData(form);
    
    const btn = document.getElementById("submitBtn");
    const btnText = document.querySelector(".btn-text");
    const loader = document.querySelector(".loader");
    const resultsContainer = document.getElementById("resultsContainer");
    
    btn.disabled = true;
    btnText.style.display = "none";
    loader.style.display = "block";
    resultsContainer.classList.add("hidden");
    
    try {
        const response = await fetch("/api/verify", {
            method: "POST",
            body: formData
        });
        
        if (!response.ok) throw new Error("Server error");
        
        const data = await response.json();
        
        const verdictTag = document.getElementById("finalVerdictTag");
        verdictTag.textContent = data.final_verdict;
        verdictTag.style.backgroundColor = data.verdict_color;
        verdictTag.style.color = "#fff";
        verdictTag.style.boxShadow = `0 0 15px ${data.verdict_color}80`;
        
        const isLinguisticallyFake = data.linguistic_score.is_fake;
        const isEvidencePro = data.evidence_is_pro;
        const hasEvidence = data.evidence.length > 0;
        
        const logicFake = document.getElementById("logicFake");
        const logicStance = document.getElementById("logicStance");
        const logicSummary = document.getElementById("logicSummary");
        
        logicFake.textContent = isLinguisticallyFake ? "Failed (Looks Deceptive)" : "Passed (Looks Professional)";
        logicFake.style.color = isLinguisticallyFake ? "var(--danger)" : "var(--success)";
        
        if (!hasEvidence) {
            logicStance.textContent = "Unknown (No News Found)";
            logicStance.style.color = "var(--text-muted)";
            logicSummary.textContent = "Meaning: We couldn't find live news to fact-check this, so we are relying purely on linguistic analysis.";
        } else {
            logicStance.textContent = isEvidencePro ? "Passed (News Agrees)" : "Failed (News Disagrees)";
            logicStance.style.color = isEvidencePro ? "var(--success)" : "var(--danger)";
            
            if (!isLinguisticallyFake && isEvidencePro) {
                logicSummary.textContent = "Meaning: The text is professionally written and is backed up by live news. This is verified true.";
            } else if (isLinguisticallyFake && !isEvidencePro) {
                logicSummary.textContent = "Meaning: The text is highly deceptive and live news completely contradicts it. This is verified fake.";
            } else if (isLinguisticallyFake && isEvidencePro) {
                logicSummary.textContent = "Meaning: Live news confirms this event happened, but the text you provided is written in a highly deceptive, sensationalist, or click-bait manner.";
            } else if (!isLinguisticallyFake && !isEvidencePro) {
                logicSummary.textContent = "Meaning: The text is written very professionally (like a real news article), but live news proves that it is factually incorrect.";
            }
        }
        
        const fProb = (data.linguistic_score.prob_fake * 100).toFixed(1);
        const rProb = (data.linguistic_score.prob_real * 100).toFixed(1);
        
        document.getElementById("fakeProbVal").textContent = `${fProb}%`;
        document.getElementById("fakeProbFill").style.width = `${fProb}%`;
        document.getElementById("realProbVal").textContent = `${rProb}%`;
        document.getElementById("realProbFill").style.width = `${rProb}%`;
        
        const imgInd = document.getElementById("imageStatusIndicator");
        const imgMsg = document.getElementById("imageStatusMessage");
        imgMsg.textContent = data.image_analysis.message;
        
        if (data.image_analysis.status === "none") {
            imgInd.style.backgroundColor = "gray";
        } else if (data.image_analysis.tampered_prob < 0.5) {
            imgInd.style.backgroundColor = "var(--success)";
        } else {
            imgInd.style.backgroundColor = "var(--danger)";
        }
        
        const evidenceList = document.getElementById("evidenceList");
        evidenceList.innerHTML = "";
        
        if (data.evidence.length === 0) {
            evidenceList.innerHTML = `<p style="color: var(--text-muted); font-style: italic;">No related live news articles found to cross-reference.</p>`;
        } else {
            data.evidence.forEach(item => {
                const isPro = item.stance === "PRO";
                const div = document.createElement("div");
                div.className = `evidence-item ${isPro ? "pro" : "con"}`;
                
                div.innerHTML = `
                    <div class="evidence-source">${item.source}</div>
                    <div class="evidence-snippet">"${item.snippet}"</div>
                    <div class="evidence-stance-badge ${isPro ? "badge-pro" : "badge-con"}">
                        Stance: ${item.stance} (${(item.confidence * 100).toFixed(1)}% Confidence)
                    </div>
                `;
                evidenceList.appendChild(div);
            });
        }
        
        resultsContainer.classList.remove("hidden");
        
    } catch (error) {
        alert("An error occurred during verification. Make sure the backend is running.");
        console.error(error);
    } finally {
        btn.disabled = false;
        btnText.style.display = "block";
        loader.style.display = "none";
    }
});