Spaces:
Running
Running
File size: 3,715 Bytes
53a775c 8b0b38b fca1361 c6a5049 53a775c fca1361 53a775c e62fe12 c6a5049 e287d13 c6a5049 e287d13 e189a6a c6a5049 1a37dfc e189a6a eebea30 e189a6a fca1361 e189a6a fca1361 c6a5049 fca1361 e287d13 fca1361 53a775c eebea30 fca1361 53a775c fca1361 de117b4 fca1361 eebea30 fca1361 f14b62f e189a6a e62fe12 e189a6a e62fe12 f416d7f f14b62f 4905bdc fca1361 de117b4 fca1361 e62fe12 53a775c 81e675c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
import os
import gradio as gr
from dotenv import load_dotenv
from utils import analyze, prepare_examples
load_dotenv()
TOKEN = os.getenv("HF_TOKEN")
EXAMPLES = prepare_examples()
CSS = """
.header {
text-align: center;
padding: 2rem 1rem;
background: linear-gradient(135deg, #14b8a6 0%, #0d9488 100%);
color: white;
border-radius: 8px;
margin-bottom: 2rem;
}
.header-logo {
max-width: 400px;
height: auto;
margin: 0 auto;
display: block;
}
.header p { margin: 0.5rem 0; opacity: 0.9; }
.header a { color: white; text-decoration: underline; }
/* Hide built-in Gradio footer */
footer {
display: none !important;
}
/* Custom footer styling */
.custom-footer {
text-align: center;
padding: 1rem;
color: #888;
margin-top: 2rem;
}
"""
with gr.Blocks(
title="Visual Content Moderation",
css=CSS,
theme=gr.themes.Default(primary_hue=gr.themes.colors.teal),
analytics_enabled=False,
) as demo:
gr.HTML("""
<div class="header">
<img src="https://github.com/viddexa/moderators/releases/download/v0.1.1/logo-v2.jpeg" alt="Visual Content Moderation" class="header-logo">
<p>Official demo for the <a href="https://github.com/viddexa/moderators" target="_blank">moderators</a> package</p>
<p>
<a href="https://huggingface.co/viddexa/nsfw-detection-2-mini" target="_blank">Model: nsfw-detection-2-mini</a> |
<a href="https://huggingface.co/viddexa/nsfw-detection-2-nano" target="_blank">Model: nsfw-detection-2-nano</a> |
<a href="https://arxiv.org/abs/2312.16338" target="_blank">Arxiv</a> |
<a href="https://github.com/viddexa/moderators" target="_blank">GitHub</a> |
<a href="https://pypi.org/project/moderators/" target="_blank">PyPI</a>
</p>
</div>
""")
with gr.Accordion("📄 BibTeX entry for citation", open=False):
gr.Textbox(
value="""@article{akyon2023nudity,
title={State-of-the-art in nudity classification: A comparative analysis},
author={Akyon, Fatih Cagatay and Temizel, Alptekin},
booktitle={2023 IEEE International Conference on Acoustics, Speech, and Signal Processing Workshops (ICASSPW)},
pages={1--5},
year={2023},
organization={IEEE}
}""",
show_label=False,
lines=9,
max_lines=9,
)
with gr.Row():
with gr.Column(scale=1):
model_choice = gr.Dropdown(
choices=["viddexa/nsfw-detection-2-mini", "viddexa/nsfw-detection-2-nano"],
value="viddexa/nsfw-detection-2-mini",
label="Model",
)
with gr.Tabs():
with gr.TabItem("Upload"):
image_input = gr.Image(type="filepath", label="Image")
with gr.TabItem("URL"):
url_input = gr.Textbox(label="Image URL", placeholder="https://...")
analyze_btn = gr.Button("Analyze", variant="primary")
with gr.Column(scale=1):
output = gr.Label(label="Classification Scores", num_top_classes=5)
gr.Markdown("### 🎯 Try an Example")
gr.Examples(
examples=EXAMPLES,
inputs=[image_input, model_choice],
outputs=output,
fn=lambda img, model: analyze(img, None, model, TOKEN),
cache_examples=True,
run_on_click=True,
)
analyze_btn.click(
fn=lambda img, url, model: analyze(img, url, model, TOKEN),
inputs=[image_input, url_input, model_choice],
outputs=output,
)
gr.HTML('<div class="custom-footer">Developed by Viddexa</div>')
demo.launch() |