Update app.py
Browse files
app.py
CHANGED
|
@@ -213,47 +213,128 @@ def format_audio_results(audio_file):
|
|
| 213 |
res = analyze_audio(audio_file)
|
| 214 |
return f"### Audio Detection\nAI Probability: {res['ai_probability']:.4f}\nConfidence: {res['confidence']}\nExplanation: {res['explanation']}"
|
| 215 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
with gr.Blocks() as app:
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
|
|
|
|
|
|
| 220 |
with gr.Row():
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
|
|
|
|
| 226 |
text_page = gr.Column(visible=False)
|
| 227 |
with text_page:
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
gr.
|
| 231 |
-
|
|
|
|
| 232 |
|
|
|
|
| 233 |
image_page = gr.Column(visible=False)
|
| 234 |
with image_page:
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
gr.
|
| 238 |
-
|
| 239 |
-
|
|
|
|
| 240 |
video_page = gr.Column(visible=False)
|
| 241 |
with video_page:
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
gr.
|
| 245 |
-
|
| 246 |
-
|
| 247 |
audio_page = gr.Column(visible=False)
|
| 248 |
with audio_page:
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
gr.
|
| 252 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
|
|
|
| 258 |
|
| 259 |
-
app.launch(share=True)
|
|
|
|
| 213 |
res = analyze_audio(audio_file)
|
| 214 |
return f"### Audio Detection\nAI Probability: {res['ai_probability']:.4f}\nConfidence: {res['confidence']}\nExplanation: {res['explanation']}"
|
| 215 |
|
| 216 |
+
# with gr.Blocks() as app:
|
| 217 |
+
# home = gr.Column(visible=True)
|
| 218 |
+
# with home:
|
| 219 |
+
# gr.Markdown("## AI Multi-Modal Detector")
|
| 220 |
+
# with gr.Row():
|
| 221 |
+
# t_btn = gr.Button("Text")
|
| 222 |
+
# i_btn = gr.Button("Image")
|
| 223 |
+
# v_btn = gr.Button("Video")
|
| 224 |
+
# a_btn = gr.Button("Audio")
|
| 225 |
+
|
| 226 |
+
# text_page = gr.Column(visible=False)
|
| 227 |
+
# with text_page:
|
| 228 |
+
# inp = gr.Textbox(lines=5, placeholder="Paste text...", label="Text")
|
| 229 |
+
# out = gr.Markdown()
|
| 230 |
+
# gr.Button("Analyze").click(format_text_results, inputs=inp, outputs=out)
|
| 231 |
+
# gr.Button("Back").click(lambda: (gr.update(visible=True), gr.update(visible=False)), outputs=[home,text_page])
|
| 232 |
+
|
| 233 |
+
# image_page = gr.Column(visible=False)
|
| 234 |
+
# with image_page:
|
| 235 |
+
# inp = gr.Image(type="pil")
|
| 236 |
+
# out = gr.Markdown()
|
| 237 |
+
# gr.Button("Analyze").click(format_image_results, inputs=inp, outputs=out)
|
| 238 |
+
# gr.Button("Back").click(lambda: (gr.update(visible=True), gr.update(visible=False)), outputs=[home,image_page])
|
| 239 |
+
|
| 240 |
+
# video_page = gr.Column(visible=False)
|
| 241 |
+
# with video_page:
|
| 242 |
+
# inp = gr.Video()
|
| 243 |
+
# out = gr.Markdown()
|
| 244 |
+
# gr.Button("Analyze").click(format_video_results, inputs=inp, outputs=out)
|
| 245 |
+
# gr.Button("Back").click(lambda: (gr.update(visible=True), gr.update(visible=False)), outputs=[home,video_page])
|
| 246 |
+
|
| 247 |
+
# audio_page = gr.Column(visible=False)
|
| 248 |
+
# with audio_page:
|
| 249 |
+
# inp = gr.Audio(type="filepath")
|
| 250 |
+
# out = gr.Markdown()
|
| 251 |
+
# gr.Button("Analyze").click(format_audio_results, inputs=inp, outputs=out)
|
| 252 |
+
# gr.Button("Back").click(lambda: (gr.update(visible=True), gr.update(visible=False)), outputs=[home,audio_page])
|
| 253 |
+
|
| 254 |
+
# t_btn.click(lambda: (gr.update(visible=False), gr.update(visible=True)), outputs=[home,text_page])
|
| 255 |
+
# i_btn.click(lambda: (gr.update(visible=False), gr.update(visible=True)), outputs=[home,image_page])
|
| 256 |
+
# v_btn.click(lambda: (gr.update(visible=False), gr.update(visible=True)), outputs=[home,video_page])
|
| 257 |
+
# a_btn.click(lambda: (gr.update(visible=False), gr.update(visible=True)), outputs=[home,audio_page])
|
| 258 |
+
|
| 259 |
+
# app.launch(share=True)
|
| 260 |
with gr.Blocks() as app:
|
| 261 |
+
# Home Page
|
| 262 |
+
home_page = gr.Column(visible=True)
|
| 263 |
+
with home_page:
|
| 264 |
+
gr.Markdown("## 🏠 AI Detection Tool")
|
| 265 |
+
gr.Markdown("Select an option below to continue:")
|
| 266 |
with gr.Row():
|
| 267 |
+
text_page_btn = gr.Button("🧠 Text Detection")
|
| 268 |
+
image_page_btn = gr.Button("🖼️ Image Detection")
|
| 269 |
+
video_page_btn = gr.Button("🎬 Video Detection") # Add on home page
|
| 270 |
+
audio_page_btn = gr.Button("🎵 Audio Detection") # Add this to home page
|
| 271 |
|
| 272 |
+
# Text Page
|
| 273 |
text_page = gr.Column(visible=False)
|
| 274 |
with text_page:
|
| 275 |
+
gr.Markdown("## 🧠 Text Detection")
|
| 276 |
+
text_input = gr.Textbox(lines=5, placeholder="Paste your text here...", label="Input Text")
|
| 277 |
+
text_output = gr.Markdown("⚡ Result will appear here after submission...", label="Result")
|
| 278 |
+
analyze_text_btn = gr.Button("Analyze Text")
|
| 279 |
+
back_btn_text = gr.Button("⬅️ Back")
|
| 280 |
|
| 281 |
+
# Image Page
|
| 282 |
image_page = gr.Column(visible=False)
|
| 283 |
with image_page:
|
| 284 |
+
gr.Markdown("## 🖼️ Image Detection")
|
| 285 |
+
image_input = gr.Image(type="pil", label="Upload Image")
|
| 286 |
+
image_output = gr.Markdown("⚡ Result will appear here after image upload...", label="Result")
|
| 287 |
+
analyze_image_btn = gr.Button("Analyze Image")
|
| 288 |
+
back_btn_image = gr.Button("⬅️ Back")
|
| 289 |
+
# Video page
|
| 290 |
video_page = gr.Column(visible=False)
|
| 291 |
with video_page:
|
| 292 |
+
gr.Markdown("## 🎬 Video Detection")
|
| 293 |
+
video_input = gr.Video(label="Upload Video") # Corrected
|
| 294 |
+
video_output = gr.Markdown("⚡ Result will appear here after video upload...", label="Result")
|
| 295 |
+
analyze_video_btn = gr.Button("Analyze Video")
|
| 296 |
+
back_btn_video = gr.Button("⬅️ Back")
|
| 297 |
audio_page = gr.Column(visible=False)
|
| 298 |
with audio_page:
|
| 299 |
+
gr.Markdown("## 🎵 Audio Detection")
|
| 300 |
+
audio_input = gr.Audio(label="Upload Audio", type="filepath") # Use type="filepath" to get local path
|
| 301 |
+
audio_output = gr.Markdown("⚡ Result will appear here after audio upload...", label="Result")
|
| 302 |
+
analyze_audio_btn = gr.Button("Analyze Audio")
|
| 303 |
+
back_btn_audio = gr.Button("⬅️ Back")
|
| 304 |
+
|
| 305 |
+
def show_video_page():
|
| 306 |
+
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=True)
|
| 307 |
+
def show_audio_page():
|
| 308 |
+
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=True)
|
| 309 |
+
|
| 310 |
+
audio_page_btn.click(show_audio_page, outputs=[home_page, text_page, image_page, video_page, audio_page])
|
| 311 |
+
|
| 312 |
+
# Back button returns to home
|
| 313 |
+
# Navigation functions
|
| 314 |
+
def show_text_page():
|
| 315 |
+
return gr.update(visible=False), gr.update(visible=True), gr.update(visible=False)
|
| 316 |
+
def show_image_page():
|
| 317 |
+
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=True)
|
| 318 |
+
def show_home():
|
| 319 |
+
return gr.update(visible=True), gr.update(visible=False), gr.update(visible=False)
|
| 320 |
+
|
| 321 |
+
# Bind navigation buttons
|
| 322 |
+
text_page_btn.click(show_text_page, outputs=[home_page, text_page, image_page])
|
| 323 |
+
image_page_btn.click(show_image_page, outputs=[home_page, text_page, image_page])
|
| 324 |
+
back_btn_text.click(show_home, outputs=[home_page, text_page, image_page])
|
| 325 |
+
back_btn_image.click(show_home, outputs=[home_page, text_page, image_page])
|
| 326 |
+
video_page_btn.click(show_video_page, outputs=[home_page, text_page, image_page, video_page])
|
| 327 |
+
back_btn_video.click(lambda: (gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)),
|
| 328 |
+
outputs=[home_page, text_page, image_page, video_page])
|
| 329 |
+
back_btn_audio.click(lambda: (
|
| 330 |
+
gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
| 331 |
+
), outputs=[home_page, text_page, image_page, video_page, audio_page])
|
| 332 |
+
|
| 333 |
|
| 334 |
+
# Bind analysis buttons
|
| 335 |
+
analyze_text_btn.click(format_text_results, inputs=text_input, outputs=text_output)
|
| 336 |
+
analyze_image_btn.click(format_image_results, inputs=image_input, outputs=image_output)
|
| 337 |
+
analyze_video_btn.click(format_video_results, inputs=video_input, outputs=video_output)
|
| 338 |
+
analyze_audio_btn.click(format_audio_results, inputs=audio_input, outputs=audio_output)
|
| 339 |
|
| 340 |
+
app.launch(share=True, debug=True)
|