Spaces:
Runtime error
Runtime error
Commit
·
83ba4a0
1
Parent(s):
fdd9119
V1.1
Browse files
app.py
CHANGED
|
@@ -26,11 +26,9 @@ import gradio as gr
|
|
| 26 |
from PIL import Image
|
| 27 |
from torchvision import transforms
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
deepfake_cfg_path = "./configs/detector2.yaml"
|
| 33 |
-
|
| 34 |
|
| 35 |
|
| 36 |
# Add current directory to path
|
|
@@ -511,11 +509,80 @@ def process_image(input_image, damage_model_path, deepfake_model_path, deepfake_
|
|
| 511 |
|
| 512 |
return result_img, "\n".join(progress_info)
|
| 513 |
|
| 514 |
-
|
|
|
|
| 515 |
with gr.Blocks(title="Car Damage & Deepfake Detection") as app:
|
| 516 |
gr.Markdown("# Car Damage Detection & Deepfake Verification")
|
| 517 |
gr.Markdown("Upload an image to detect car damage and check if it's a deepfake")
|
| 518 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 519 |
with gr.Tab("Basic Interface"):
|
| 520 |
with gr.Row():
|
| 521 |
with gr.Column(scale=1):
|
|
|
|
| 26 |
from PIL import Image
|
| 27 |
from torchvision import transforms
|
| 28 |
|
| 29 |
+
DEFAULT_DAMAGE_MODEL_PATH = "./model_final.pth" # Replace with your actual path
|
| 30 |
+
DEFAULT_DEEPFAKE_MODEL_PATH = "./PoseEfficientNet_custom_laanet_model_final.pth" # Replace with your actual path
|
| 31 |
+
DEFAULT_DEEPFAKE_CFG_PATH = "./configs/detector2.yaml" # Replace with your actual path
|
|
|
|
|
|
|
| 32 |
|
| 33 |
|
| 34 |
# Add current directory to path
|
|
|
|
| 509 |
|
| 510 |
return result_img, "\n".join(progress_info)
|
| 511 |
|
| 512 |
+
|
| 513 |
+
def create_gradio_interface():
|
| 514 |
with gr.Blocks(title="Car Damage & Deepfake Detection") as app:
|
| 515 |
gr.Markdown("# Car Damage Detection & Deepfake Verification")
|
| 516 |
gr.Markdown("Upload an image to detect car damage and check if it's a deepfake")
|
| 517 |
|
| 518 |
+
with gr.Tab("Basic Interface"):
|
| 519 |
+
with gr.Row():
|
| 520 |
+
with gr.Column(scale=1):
|
| 521 |
+
input_image = gr.Image(type="numpy", label="Input Image")
|
| 522 |
+
|
| 523 |
+
# Simple controls
|
| 524 |
+
skip_damage = gr.Checkbox(label="Skip Damage Detection", value=False)
|
| 525 |
+
damage_threshold = gr.Slider(minimum=0.1, maximum=1.0, value=0.7, step=0.05,
|
| 526 |
+
label="Damage Detection Threshold")
|
| 527 |
+
deepfake_threshold = gr.Slider(minimum=0.1, maximum=1.0, value=0.5, step=0.05,
|
| 528 |
+
label="Deepfake Detection Threshold")
|
| 529 |
+
device = gr.Dropdown(choices=["auto", "cuda", "cpu", "mps"], value="auto",
|
| 530 |
+
label="Computation Device")
|
| 531 |
+
|
| 532 |
+
process_btn = gr.Button("Process Image", variant="primary")
|
| 533 |
+
|
| 534 |
+
with gr.Column(scale=1):
|
| 535 |
+
output_image = gr.Image(type="numpy", label="Result")
|
| 536 |
+
output_text = gr.Textbox(label="Detection Results", lines=10)
|
| 537 |
+
|
| 538 |
+
with gr.Tab("Advanced Settings"):
|
| 539 |
+
with gr.Row():
|
| 540 |
+
with gr.Column():
|
| 541 |
+
# Create empty textboxes - values will be provided by the wrapper function
|
| 542 |
+
damage_model_path = gr.Textbox(label="Damage Model Path (optional)",
|
| 543 |
+
placeholder="Leave blank to use default model")
|
| 544 |
+
deepfake_model_path = gr.Textbox(label="Deepfake Model Path (optional)",
|
| 545 |
+
placeholder="Leave blank to use default model")
|
| 546 |
+
deepfake_cfg_path = gr.Textbox(label="Deepfake Config Path (optional)",
|
| 547 |
+
placeholder="Leave blank to use default config")
|
| 548 |
+
|
| 549 |
+
# Create a wrapper function that applies default values when fields are empty
|
| 550 |
+
def process_with_defaults(input_image, damage_path, deepfake_path, cfg_path,
|
| 551 |
+
damage_threshold, deepfake_threshold, skip_damage, device):
|
| 552 |
+
# Use default paths if none provided
|
| 553 |
+
actual_damage_path = damage_path if damage_path.strip() else DEFAULT_DAMAGE_MODEL_PATH
|
| 554 |
+
actual_deepfake_path = deepfake_path if deepfake_path.strip() else DEFAULT_DEEPFAKE_MODEL_PATH
|
| 555 |
+
actual_cfg_path = cfg_path if cfg_path.strip() else DEFAULT_DEEPFAKE_CFG_PATH
|
| 556 |
+
|
| 557 |
+
# Call the original process function with the actual paths
|
| 558 |
+
return process_image(
|
| 559 |
+
input_image, actual_damage_path, actual_deepfake_path, actual_cfg_path,
|
| 560 |
+
damage_threshold, deepfake_threshold, skip_damage, device
|
| 561 |
+
)
|
| 562 |
+
|
| 563 |
+
# Connect the wrapper function
|
| 564 |
+
process_btn.click(
|
| 565 |
+
fn=process_with_defaults,
|
| 566 |
+
inputs=[
|
| 567 |
+
input_image,
|
| 568 |
+
damage_model_path,
|
| 569 |
+
deepfake_model_path,
|
| 570 |
+
deepfake_cfg_path,
|
| 571 |
+
damage_threshold,
|
| 572 |
+
deepfake_threshold,
|
| 573 |
+
skip_damage,
|
| 574 |
+
device
|
| 575 |
+
],
|
| 576 |
+
outputs=[output_image, output_text]
|
| 577 |
+
)
|
| 578 |
+
|
| 579 |
+
# Examples
|
| 580 |
+
gr.Markdown("## Examples")
|
| 581 |
+
gr.Markdown("Note: Examples will use the default models if you don't specify custom paths.")
|
| 582 |
+
|
| 583 |
+
return app gr.Markdown("# Car Damage Detection & Deepfake Verification")
|
| 584 |
+
gr.Markdown("Upload an image to detect car damage and check if it's a deepfake")
|
| 585 |
+
|
| 586 |
with gr.Tab("Basic Interface"):
|
| 587 |
with gr.Row():
|
| 588 |
with gr.Column(scale=1):
|