File size: 3,391 Bytes
56e3c29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c29b197
56e3c29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# import streamlit as st
# import numpy as np
# import cv2
# import tempfile
# import os

# # ---- Page Configuration ----
# st.set_page_config(page_title="Fake & Deepfake Detection", layout="wide")

# st.title("πŸ“° Fake News & Deepfake Detection Tool")
# st.write("πŸš€ Detect Fake News, Deepfake Images, and Videos using AI")

# # ---- Fake News Detection Section ----
# st.subheader("πŸ“ Fake News Detection")
# news_input = st.text_area("Enter News Text:", "Type here...")

# if st.button("Check News"):
#     st.write("πŸ” Processing...")
#     # Fake news detection logic (Placeholder)
#     st.success("βœ… Result: This news is FAKE.")  # Replace with ML Model

# # ---- Deepfake Image Detection Section ----
# st.subheader("πŸ“Έ Deepfake Image Detection")
# uploaded_image = st.file_uploader("Upload an Image", type=["jpg", "png", "jpeg"])

# if uploaded_image is not None:
#     st.image(uploaded_image, caption="Uploaded Image", use_column_width=True)
#     if st.button("Analyze Image"):
#         st.write("πŸ” Processing...")
#         # Deepfake detection logic (Placeholder)
#         st.error("⚠️ Result: This image is a Deepfake.")  # Replace with model

# # ---- Deepfake Video Detection Section ----
# st.subheader("πŸŽ₯ Deepfake Video Detection")
# uploaded_video = st.file_uploader("Upload a Video", type=["mp4", "avi", "mov"])

# if uploaded_video is not None:
#     st.video(uploaded_video)
#     if st.button("Analyze Video"):
#         st.write("πŸ” Processing...")
#         # Deepfake video detection logic (Placeholder)
#         st.warning("⚠️ Result: This video contains Deepfake elements.")  # Replace with model

# st.markdown("πŸ”Ή **Developed for Fake News & Deepfake Detection Hackathon**")


import gradio as gr
import cv2
import numpy as np

# βœ… Image Size Limit (MB) 
MAX_IMAGE_SIZE_MB = 5  # 5MB se zyada allow nahi karega

# βœ… Video Size Limit (MB) 
MAX_VIDEO_SIZE_MB = 20  # 20MB se zyada allow nahi karega

# βœ… Image Processing Function
def process_image(image):
    if image is None:
        return "❌ No image uploaded!"
    
    # βœ… Image Resize (Optional: 512x512)
    image = cv2.resize(image, (512, 512))  
    return image

# βœ… Video Processing Function
def process_video(video_path):
    if video_path is None:
        return "❌ No video uploaded!"
    
    # βœ… Video Size Check
    import os
    file_size_mb = os.path.getsize(video_path) / (1024 * 1024)
    if file_size_mb > MAX_VIDEO_SIZE_MB:
        return f"❌ Video is too large! (Size: {file_size_mb:.2f}MB) - Limit: {MAX_VIDEO_SIZE_MB}MB"
    
    return f"βœ… Video uploaded successfully! (Size: {file_size_mb:.2f}MB)"

# βœ… Gradio Interface
with gr.Blocks() as app:
    gr.Markdown("## πŸ•΅οΈβ€β™‚οΈ Fake News & Deepfake Detection Tool")

    with gr.Row():
        img_input = gr.Image(type="numpy", label="πŸ–Ό Upload Image (Max: 5MB)")
        img_output = gr.Image(label="πŸ“Œ Processed Image")
        img_button = gr.Button("πŸ” Detect Image")

    img_button.click(process_image, inputs=img_input, outputs=img_output)

    with gr.Row():
        video_input = gr.File(label="πŸŽ₯ Upload Video (Max: 20MB)", file_types=[".mp4"])
        video_output = gr.Textbox(label="πŸ“Œ Video Status")
        video_button = gr.Button("πŸ” Detect Video")

    video_button.click(process_video, inputs=video_input, outputs=video_output)

app.launch()