Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
# Load models
|
| 6 |
+
text_model = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-fake-news-detection")
|
| 7 |
+
image_model = pipeline("image-classification", model="prithivMLmods/Deep-Fake-Detector-v2-Model")
|
| 8 |
+
|
| 9 |
+
# Text detection function
|
| 10 |
+
def detect_text_misinformation(text):
|
| 11 |
+
if not text.strip():
|
| 12 |
+
return "Please enter some text.", None
|
| 13 |
+
result = text_model(text)[0]
|
| 14 |
+
return f"Prediction: {result['label']}", f"Confidence: {result['score']:.2f}"
|
| 15 |
+
|
| 16 |
+
# Image detection function
|
| 17 |
+
def detect_image_deepfake(image):
|
| 18 |
+
result = image_model(image)[0]
|
| 19 |
+
label_map = {
|
| 20 |
+
"LABEL_0": ("Unauthentic", "❌"),
|
| 21 |
+
"LABEL_1": ("Authentic", "✅")
|
| 22 |
+
}
|
| 23 |
+
label, icon = label_map.get(result['label'].upper(), (result['label'], "❓"))
|
| 24 |
+
return f"{icon} Prediction: {label}", f"Confidence: {result['score']:.2f}"
|
| 25 |
+
|
| 26 |
+
# Gradio Interface
|
| 27 |
+
text_interface = gr.Interface(
|
| 28 |
+
fn=detect_text_misinformation,
|
| 29 |
+
inputs=gr.Textbox(lines=3, placeholder="Enter a news statement or claim..."),
|
| 30 |
+
outputs=["text", "text"],
|
| 31 |
+
title="📰 Misinformation Detection"
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
image_interface = gr.Interface(
|
| 35 |
+
fn=detect_image_deepfake,
|
| 36 |
+
inputs=gr.Image(type="pil"),
|
| 37 |
+
outputs=["text", "text"],
|
| 38 |
+
title="🖼️ Deepfake Image Detection"
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
demo = gr.TabbedInterface([text_interface, image_interface], ["Text Misinformation", "Image Deepfake"])
|
| 42 |
+
demo.launch()
|