TruthForge-MVP / app.py
Tpayne101's picture
Update app.py
602b268 verified
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()