File size: 1,442 Bytes
cfe3e94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from transformers import pipeline
from PIL import Image
import gradio as gr

# Load models
text_model = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-fake-news-detection")
image_model = pipeline("image-classification", model="prithivMLmods/Deep-Fake-Detector-v2-Model")

# Text detection function
def detect_text_misinformation(text):
    if not text.strip():
        return "Please enter some text.", None
    result = text_model(text)[0]
    return f"Prediction: {result['label']}", f"Confidence: {result['score']:.2f}"

# Image detection function
def detect_image_deepfake(image):
    result = image_model(image)[0]
    label_map = {
        "LABEL_0": ("Unauthentic", "❌"),
        "LABEL_1": ("Authentic", "✅")
    }
    label, icon = label_map.get(result['label'].upper(), (result['label'], "❓"))
    return f"{icon} Prediction: {label}", f"Confidence: {result['score']:.2f}"

# Gradio Interface
text_interface = gr.Interface(
    fn=detect_text_misinformation,
    inputs=gr.Textbox(lines=3, placeholder="Enter a news statement or claim..."),
    outputs=["text", "text"],
    title="📰 Misinformation Detection"
)

image_interface = gr.Interface(
    fn=detect_image_deepfake,
    inputs=gr.Image(type="pil"),
    outputs=["text", "text"],
    title="🖼️ Deepfake Image Detection"
)

demo = gr.TabbedInterface([text_interface, image_interface], ["Text Misinformation", "Image Deepfake"])
demo.launch()