Spaces:
Sleeping
Sleeping
onuruls
commited on
Commit
·
7faf6fd
1
Parent(s):
70e1e32
add img examples
Browse files- .gitattributes +1 -0
- .gitignore +3 -0
- app.py +17 -7
- examples/gambling_alcohol.jpg +3 -0
- examples/gambling_smoke_alcohol.jpg +3 -0
- examples/smoke_alcohol.jpg +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.jpg filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.idea/
|
| 2 |
+
__pycache__/
|
| 3 |
+
src/models/__pycache__/
|
app.py
CHANGED
|
@@ -17,7 +17,6 @@ try:
|
|
| 17 |
except Exception:
|
| 18 |
pass
|
| 19 |
|
| 20 |
-
|
| 21 |
APP_TITLE = "Content Moderation Demo (Image & Video)"
|
| 22 |
APP_DESC = """
|
| 23 |
Minimal prototype: image/video analysis, model & category selection, and threshold control.
|
|
@@ -25,6 +24,13 @@ Minimal prototype: image/video analysis, model & category selection, and thresho
|
|
| 25 |
|
| 26 |
MODEL_NAMES = list(REGISTRY.keys())
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
# ---------- Shared ----------
|
| 29 |
def on_model_change(model_name):
|
| 30 |
if model_name in NUDENET_ONLY:
|
|
@@ -97,11 +103,6 @@ def analyze_video(model_name, video_file, selected_categories, threshold, sampli
|
|
| 97 |
|
| 98 |
rows = []
|
| 99 |
for seg_id, (a, b) in enumerate(union_runs, start=1):
|
| 100 |
-
for i in range(a, b + 1):
|
| 101 |
-
st = frame_stats.get(i)
|
| 102 |
-
if not st:
|
| 103 |
-
continue
|
| 104 |
-
|
| 105 |
cat_counts = {c: 0 for c in req}
|
| 106 |
cat_maxp = {c: 0.0 for c in req}
|
| 107 |
for i in range(a, b + 1):
|
|
@@ -141,7 +142,6 @@ def analyze_video(model_name, video_file, selected_categories, threshold, sampli
|
|
| 141 |
|
| 142 |
return df, out_video
|
| 143 |
|
| 144 |
-
|
| 145 |
# ---------- UI ----------
|
| 146 |
with gr.Blocks(title=APP_TITLE, css=".wrap-row { gap: 16px; }") as demo:
|
| 147 |
gr.Markdown(f"# {APP_TITLE}")
|
|
@@ -166,6 +166,16 @@ with gr.Blocks(title=APP_TITLE, css=".wrap-row { gap: 16px; }") as demo:
|
|
| 166 |
btn.click(analyze_image, inputs=[model_dd, inp_img, categories, threshold],
|
| 167 |
outputs=[verdict, scores_df, extra_tags])
|
| 168 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
with gr.Tab("Video"):
|
| 170 |
with gr.Row(elem_classes=["wrap-row"]):
|
| 171 |
with gr.Column(scale=1, min_width=360):
|
|
|
|
| 17 |
except Exception:
|
| 18 |
pass
|
| 19 |
|
|
|
|
| 20 |
APP_TITLE = "Content Moderation Demo (Image & Video)"
|
| 21 |
APP_DESC = """
|
| 22 |
Minimal prototype: image/video analysis, model & category selection, and threshold control.
|
|
|
|
| 24 |
|
| 25 |
MODEL_NAMES = list(REGISTRY.keys())
|
| 26 |
|
| 27 |
+
IMG_EXAMPLES = [
|
| 28 |
+
# [model, image_path, categories, threshold]
|
| 29 |
+
["clip-multilabel", "examples/gambling_alcohol.jpg", ALL_CATEGORIES, 0.50],
|
| 30 |
+
["wdeva02-multilabel", "examples/smoke_alcohol.jpg", ALL_CATEGORIES, 0.50],
|
| 31 |
+
["animetimm-multilabel", "examples/gambling_smoke_alcohol.jpg", ALL_CATEGORIES, 0.50],
|
| 32 |
+
]
|
| 33 |
+
|
| 34 |
# ---------- Shared ----------
|
| 35 |
def on_model_change(model_name):
|
| 36 |
if model_name in NUDENET_ONLY:
|
|
|
|
| 103 |
|
| 104 |
rows = []
|
| 105 |
for seg_id, (a, b) in enumerate(union_runs, start=1):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
cat_counts = {c: 0 for c in req}
|
| 107 |
cat_maxp = {c: 0.0 for c in req}
|
| 108 |
for i in range(a, b + 1):
|
|
|
|
| 142 |
|
| 143 |
return df, out_video
|
| 144 |
|
|
|
|
| 145 |
# ---------- UI ----------
|
| 146 |
with gr.Blocks(title=APP_TITLE, css=".wrap-row { gap: 16px; }") as demo:
|
| 147 |
gr.Markdown(f"# {APP_TITLE}")
|
|
|
|
| 166 |
btn.click(analyze_image, inputs=[model_dd, inp_img, categories, threshold],
|
| 167 |
outputs=[verdict, scores_df, extra_tags])
|
| 168 |
|
| 169 |
+
gr.Examples(
|
| 170 |
+
label="Try an example (Image)",
|
| 171 |
+
examples=IMG_EXAMPLES,
|
| 172 |
+
inputs=[model_dd, inp_img, categories, threshold],
|
| 173 |
+
outputs=[verdict, scores_df, extra_tags],
|
| 174 |
+
fn=analyze_image,
|
| 175 |
+
run_on_click=True,
|
| 176 |
+
cache_examples=False,
|
| 177 |
+
)
|
| 178 |
+
|
| 179 |
with gr.Tab("Video"):
|
| 180 |
with gr.Row(elem_classes=["wrap-row"]):
|
| 181 |
with gr.Column(scale=1, min_width=360):
|
examples/gambling_alcohol.jpg
ADDED
|
Git LFS Details
|
examples/gambling_smoke_alcohol.jpg
ADDED
|
Git LFS Details
|
examples/smoke_alcohol.jpg
ADDED
|
Git LFS Details
|