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("""

Official demo for the moderators package

Model: nsfw-detection-2-mini | Model: nsfw-detection-2-nano | Arxiv | GitHub | PyPI

""") 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('') demo.launch()