ui_test_001 / app.py
woutn-223's picture
Create app.py
cfe3e94 verified
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()