LPX55
commited on
Commit
·
87da6f6
1
Parent(s):
c7db87b
test2
Browse files
app.py
CHANGED
@@ -15,6 +15,7 @@ import concurrent.futures
|
|
15 |
import ast
|
16 |
import torch
|
17 |
from gradio_log import Log
|
|
|
18 |
|
19 |
from utils.utils import softmax, augment_image, preprocess_resize_256, preprocess_resize_224, postprocess_pipeline, postprocess_logits, postprocess_binary_output, to_float_scalar, infer_gradio_api, preprocess_gradio_api, postprocess_gradio_api
|
20 |
from utils.onnx_helpers import preprocess_onnx_input, postprocess_onnx_output, infer_onnx_model
|
@@ -33,7 +34,7 @@ from utils.registry import register_model, MODEL_REGISTRY, ModelEntry
|
|
33 |
from agents.ensemble_weights import ModelWeightManager
|
34 |
from transformers import pipeline, AutoImageProcessor, SwinForImageClassification, Swinv2ForImageClassification, AutoFeatureExtractor, AutoModelForImageClassification
|
35 |
from torchvision import transforms
|
36 |
-
|
37 |
logging.basicConfig(level=logging.INFO)
|
38 |
logger = logging.getLogger(__name__)
|
39 |
os.environ['HF_HUB_CACHE'] = './models'
|
@@ -46,7 +47,58 @@ log_queue, gradio_handler = setup_gradio_logging()
|
|
46 |
|
47 |
LOCAL_LOG_DIR = "./hf_inference_logs"
|
48 |
HF_DATASET_NAME="aiwithoutborders-xyz/degentic_rd0"
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
# Custom JSON Encoder to handle numpy types
|
52 |
class NumpyEncoder(json.JSONEncoder):
|
@@ -417,7 +469,6 @@ detection_model_eval_playground = gr.Interface(
|
|
417 |
),
|
418 |
gr.JSON(label="Raw Model Results", visible=False),
|
419 |
gr.Markdown(label="Consensus", value="")
|
420 |
-
Log(anomaly_detection_results, dark=True, xterm_font_size=12)
|
421 |
],
|
422 |
title="Multi-Model Ensemble + Agentic Coordinated Deepfake Detection (Paper in Progress)",
|
423 |
description="The detection of AI-generated images has entered a critical inflection point. While existing solutions struggle with outdated datasets and inflated claims, our approach prioritizes agility, community collaboration, and an offensive approach to deepfake detection.",
|
@@ -622,6 +673,11 @@ footer = gr.Markdown(footerMD, elem_classes="footer")
|
|
622 |
|
623 |
with gr.Blocks() as app:
|
624 |
demo.render()
|
|
|
|
|
|
|
|
|
|
|
625 |
footer.render()
|
626 |
|
627 |
|
|
|
15 |
import ast
|
16 |
import torch
|
17 |
from gradio_log import Log
|
18 |
+
from pathlib import Path
|
19 |
|
20 |
from utils.utils import softmax, augment_image, preprocess_resize_256, preprocess_resize_224, postprocess_pipeline, postprocess_logits, postprocess_binary_output, to_float_scalar, infer_gradio_api, preprocess_gradio_api, postprocess_gradio_api
|
21 |
from utils.onnx_helpers import preprocess_onnx_input, postprocess_onnx_output, infer_onnx_model
|
|
|
34 |
from agents.ensemble_weights import ModelWeightManager
|
35 |
from transformers import pipeline, AutoImageProcessor, SwinForImageClassification, Swinv2ForImageClassification, AutoFeatureExtractor, AutoModelForImageClassification
|
36 |
from torchvision import transforms
|
37 |
+
load_dotenv()
|
38 |
logging.basicConfig(level=logging.INFO)
|
39 |
logger = logging.getLogger(__name__)
|
40 |
os.environ['HF_HUB_CACHE'] = './models'
|
|
|
47 |
|
48 |
LOCAL_LOG_DIR = "./hf_inference_logs"
|
49 |
HF_DATASET_NAME="aiwithoutborders-xyz/degentic_rd0"
|
50 |
+
|
51 |
+
|
52 |
+
class CustomFormatter(logging.Formatter):
|
53 |
+
|
54 |
+
green = "\x1b[32;20m"
|
55 |
+
blue = "\x1b[34;20m"
|
56 |
+
yellow = "\x1b[33;20m"
|
57 |
+
red = "\x1b[31;20m"
|
58 |
+
bold_red = "\x1b[31;1m"
|
59 |
+
reset = "\x1b[0m"
|
60 |
+
format = "%(asctime)s - %(levelname)s - %(message)s (%(filename)s:%(lineno)d)"
|
61 |
+
|
62 |
+
FORMATS = {
|
63 |
+
logging.DEBUG: blue + format + reset,
|
64 |
+
logging.INFO: green + format + reset,
|
65 |
+
logging.WARNING: yellow + format + reset,
|
66 |
+
logging.ERROR: red + format + reset,
|
67 |
+
logging.CRITICAL: bold_red + format + reset,
|
68 |
+
}
|
69 |
+
|
70 |
+
def format(self, record):
|
71 |
+
log_fmt = self.FORMATS.get(record.levelno)
|
72 |
+
formatter = logging.Formatter(log_fmt)
|
73 |
+
return formatter.format(record)
|
74 |
+
|
75 |
+
|
76 |
+
formatter = CustomFormatter()
|
77 |
+
|
78 |
+
log_file = "/tmp/gradio_log.txt"
|
79 |
+
Path(log_file).touch()
|
80 |
+
|
81 |
+
ch = logging.FileHandler(log_file)
|
82 |
+
ch.setLevel(logging.DEBUG)
|
83 |
+
ch.setFormatter(formatter)
|
84 |
+
|
85 |
+
logger = logging.getLogger("gradio_log")
|
86 |
+
logger.setLevel(logging.DEBUG)
|
87 |
+
for handler in logger.handlers:
|
88 |
+
logger.removeHandler(handler)
|
89 |
+
logger.addHandler(ch)
|
90 |
+
|
91 |
+
|
92 |
+
logger.info("The logs will be displayed in here.")
|
93 |
+
|
94 |
+
|
95 |
+
def create_log_handler(level):
|
96 |
+
def l(text):
|
97 |
+
getattr(logger, level)(text)
|
98 |
+
|
99 |
+
return l
|
100 |
+
|
101 |
+
|
102 |
|
103 |
# Custom JSON Encoder to handle numpy types
|
104 |
class NumpyEncoder(json.JSONEncoder):
|
|
|
469 |
),
|
470 |
gr.JSON(label="Raw Model Results", visible=False),
|
471 |
gr.Markdown(label="Consensus", value="")
|
|
|
472 |
],
|
473 |
title="Multi-Model Ensemble + Agentic Coordinated Deepfake Detection (Paper in Progress)",
|
474 |
description="The detection of AI-generated images has entered a critical inflection point. While existing solutions struggle with outdated datasets and inflated claims, our approach prioritizes agility, community collaboration, and an offensive approach to deepfake detection.",
|
|
|
673 |
|
674 |
with gr.Blocks() as app:
|
675 |
demo.render()
|
676 |
+
with gr.Row():
|
677 |
+
for l in ["debug", "info", "warning", "error", "critical"]:
|
678 |
+
button = gr.Button(f"log as {l}")
|
679 |
+
button.click(fn=create_log_handler(l), inputs=text)
|
680 |
+
Log(log_file, dark=True).render()
|
681 |
footer.render()
|
682 |
|
683 |
|