ghengx commited on
Commit
7af2795
·
1 Parent(s): b50e226

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +135 -0
app.py ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ import warnings
4
+
5
+ from huggingface_hub import Repository
6
+ from huggingface_hub import login
7
+
8
+ warnings.filterwarnings("ignore")
9
+
10
+ login(token = os.environ['HF_TOKEN'])
11
+
12
+ from model import AIContentDetector
13
+
14
+ repo = Repository(
15
+ local_dir="",
16
+ repo_type="dataset",
17
+ clone_from=os.environ['DATASET'],
18
+ token=True
19
+ )
20
+ repo.git_pull()
21
+
22
+ # Initialize the detector
23
+ detector = AIContentDetector()
24
+
25
+ def analyze_image(image):
26
+ """Wrapper function for image analysis."""
27
+ if image is None:
28
+ return "Please upload an image", 0
29
+
30
+ result, confidence = detector.detect_ai_image(image)
31
+ return result, confidence
32
+
33
+ def analyze_video(video):
34
+ """Wrapper function for video analysis."""
35
+ if video is None:
36
+ return "Please upload a video", 0
37
+
38
+ result, confidence = detector.detect_ai_video(video)
39
+ return result, confidence
40
+
41
+ def analyze_audio(audio):
42
+ """Wrapper function for audio analysis."""
43
+ if audio is None:
44
+ return "Please upload an audio file", 0
45
+
46
+ result, confidence = detector.detect_ai_audio(audio)
47
+ return result, confidence
48
+
49
+ # Create the Gradio interface
50
+ with gr.Blocks(title="GuanFu - AI Content Detector", theme=gr.themes.Soft()) as app:
51
+ gr.Markdown(
52
+ """
53
+ # 🕵️ GuanFu - AI Content Detector
54
+
55
+ Upload images, videos, or audio files to detect if they were generated by AI.
56
+
57
+ **Note**: This is a demonstration app. Real AI detection requires specialized models trained on large datasets of AI vs human-generated content.
58
+ """
59
+ )
60
+
61
+ with gr.Tabs():
62
+ # Image Detection Tab
63
+ with gr.TabItem("🖼️ Image Detection"):
64
+ gr.Markdown("### Upload an image to check if it's AI-generated")
65
+
66
+ with gr.Row():
67
+ with gr.Column():
68
+ image_input = gr.Image(type="pil", label="Upload Image")
69
+ image_button = gr.Button("Analyze Image", variant="primary")
70
+
71
+ with gr.Column():
72
+ image_result = gr.Textbox(label="Detection Result", interactive=False)
73
+ image_confidence = gr.Number(label="Confidence Score (%)", interactive=False)
74
+
75
+ image_button.click(
76
+ fn=analyze_image,
77
+ inputs=image_input,
78
+ outputs=[image_result, image_confidence]
79
+ )
80
+
81
+ # Video Detection Tab
82
+ with gr.TabItem("🎥 Video Detection"):
83
+ gr.Markdown("### Upload a video to check if it's AI-generated")
84
+
85
+ with gr.Row():
86
+ with gr.Column():
87
+ video_input = gr.Video(label="Upload Video")
88
+ video_button = gr.Button("Analyze Video", variant="primary")
89
+
90
+ with gr.Column():
91
+ video_result = gr.Textbox(label="Detection Result", interactive=False)
92
+ video_confidence = gr.Number(label="Confidence Score (%)", interactive=False)
93
+
94
+ video_button.click(
95
+ fn=analyze_video,
96
+ inputs=video_input,
97
+ outputs=[video_result, video_confidence]
98
+ )
99
+
100
+ # Audio Detection Tab
101
+ with gr.TabItem("🎵 Audio Detection"):
102
+ gr.Markdown("### Upload an audio file to check if it's AI-generated")
103
+
104
+ with gr.Row():
105
+ with gr.Column():
106
+ audio_input = gr.Audio(type="filepath", label="Upload Audio")
107
+ audio_button = gr.Button("Analyze Audio", variant="primary")
108
+
109
+ with gr.Column():
110
+ audio_result = gr.Textbox(label="Detection Result", interactive=False)
111
+ audio_confidence = gr.Number(label="Confidence Score (%)", interactive=False)
112
+
113
+ audio_button.click(
114
+ fn=analyze_audio,
115
+ inputs=audio_input,
116
+ outputs=[audio_result, audio_confidence]
117
+ )
118
+
119
+ gr.Markdown(
120
+ """
121
+ ---
122
+ ### How it works:
123
+ - **Images**: Analyzes statistical properties, dimensions, and visual patterns
124
+ - **Videos**: Examines multiple frames and temporal consistency
125
+ - **Audio**: Analyzes spectral features and regularity patterns
126
+
127
+ ### Limitations:
128
+ - This is a demonstration using heuristic methods
129
+ - Production systems would use specialized AI detection models
130
+ - Results are estimates and should not be considered definitive
131
+ """
132
+ )
133
+
134
+ if __name__ == "__main__":
135
+ app.launch(share=True, server_name="0.0.0.0")