File size: 2,113 Bytes
ee6e31d
 
 
 
 
602b268
ee6e31d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import pipeline
import torch  # For device handling

# Load a pre-trained fake news detection model
classifier = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-fake-news-detection", device=0 if torch.cuda.is_available() else -1)

def detect_misinfo(text):
    # Run inference on the input text
    result = classifier(text)[0]
    label = result['label']  # 'FAKE' or 'REAL'
    score = result['score']  # Confidence 0-1
    
    # Convert to trust score (0-100)
    trust_score = int(score * 100) if label == 'REAL' else int((1 - score) * 100)
    
    # Add a simple explanation
    explanation = f"Label: {label}. Confidence: {score:.2f}. Trust Score: {trust_score}/100. (Higher = more credible)"
    
    return trust_score, explanation

def submit_feedback(text, score, feedback):
    # For now, just return a thank you (later, log to a dataset)
    return f"Thanks for feedback on '{text[:50]}...'. Score was {score}. We'll use this to improve!"

# Create the Gradio interface
with gr.Blocks(title="TruthForge MVP") as demo:
    gr.Markdown("# TruthForge MVP: AI Misinfo Detector")
    gr.Markdown("Paste a claim or article text. Get a trust score. Help verify!")
    
    with gr.Row():
        input_text = gr.Textbox(label="Enter Text to Check", placeholder="e.g., 'The moon landing was faked.'", lines=5)
    
    check_button = gr.Button("Scan for Trust")
    
    with gr.Row():
        output_score = gr.Number(label="Trust Score (0-100)")
        output_explain = gr.Textbox(label="Explanation")
    
    check_button.click(fn=detect_misinfo, inputs=input_text, outputs=[output_score, output_explain])
    
    gr.Markdown("## Community Feedback (Help Build the Network)")
    feedback_text = gr.Textbox(label="Your Verification Notes", placeholder="e.g., 'This is false because source X says Y.'")
    feedback_button = gr.Button("Submit Feedback")
    feedback_output = gr.Textbox(label="Response")
    
    feedback_button.click(fn=submit_feedback, inputs=[input_text, output_score, feedback_text], outputs=feedback_output)

demo.launch()